#include <stdio.h>
#include <math.h>
int main() {
// パラメータの定義
double R = 3000.0; // 抵抗 (オーム)
double L = 0.001; // インダクタンス (ヘンリー)
double V_E = 5.0; // 電源電圧 (ボルト)
int steps = 10; // 計算ステップ数を10に制限
double t_max = 0.001; // 計算する最大時間 (秒)
int i; // ループ変数
// 時定数 τ = L / R
tau = L / R;
// CSV形式で時間と電流のデータを出力
printf("Time(s),Current(A)\n"); for (i = 0; i <= steps; i++) {
time = t_max
* i
/ steps
; I
= (V_E
/ R
) * (1 - exp(-time / tau
)); // 電流 I(t) の計算式を修正 }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CgppbnQgbWFpbigpIHsKICAgIC8vIOODkeODqeODoeODvOOCv+OBruWumue+qQogICAgZG91YmxlIFIgPSAzMDAwLjA7ICAvLyDmirXmipcgKOOCquODvOODoCkKICAgIGRvdWJsZSBMID0gMC4wMDE7ICAgLy8g44Kk44Oz44OA44Kv44K/44Oz44K5ICjjg5jjg7Pjg6rjg7wpCiAgICBkb3VibGUgVl9FID0gNS4wOyAgIC8vIOmbu+a6kOmbu+WcpyAo44Oc44Or44OIKQogICAgZG91YmxlIHRpbWUsIEksIHRhdTsKICAgIGludCBzdGVwcyA9IDEwOyAgICAvLyDoqIjnrpfjgrnjg4bjg4Pjg5fmlbDjgpIxMOOBq+WItumZkAogICAgZG91YmxlIHRfbWF4ID0gMC4wMDE7IC8vIOioiOeul+OBmeOCi+acgOWkp+aZgumWkyAo56eSKQogICAgaW50IGk7ICAvLyDjg6vjg7zjg5flpInmlbAKCiAgICAvLyDmmYLlrprmlbAgz4QgPSBMIC8gUgogICAgdGF1ID0gTCAvIFI7CgogICAgLy8gQ1NW5b2i5byP44Gn5pmC6ZaT44Go6Zu75rWB44Gu44OH44O844K/44KS5Ye65YqbCiAgICBwcmludGYoIlRpbWUocyksQ3VycmVudChBKVxuIik7CiAgICBmb3IgKGkgPSAwOyBpIDw9IHN0ZXBzOyBpKyspIHsKICAgICAgICB0aW1lID0gdF9tYXggKiBpIC8gc3RlcHM7CiAgICAgICAgSSA9IChWX0UgLyBSKSAqICgxIC0gZXhwKC10aW1lIC8gdGF1KSk7ICAvLyDpm7vmtYEgSSh0KSDjga7oqIjnrpflvI/jgpLkv67mraMKICAgICAgICBwcmludGYoIiVmLCVmXG4iLCB0aW1lLCBJKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=
Time(s),Current(A)
0.000000,0.000000
0.000100,0.001667
0.000200,0.001667
0.000300,0.001667
0.000400,0.001667
0.000500,0.001667
0.000600,0.001667
0.000700,0.001667
0.000800,0.001667
0.000900,0.001667
0.001000,0.001667