#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;
// 時間変化に伴う電流 I(t) を計算
printf("Time(s)\tCurrent(A)\n"); for (i = 0; i <= steps; i++) {
time = t_max
* i
/ steps
; I
= (V_E
/ R
) * (1 - exp(-time / tau
)); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CgppbnQgbWFpbigpIHsKICAgIC8vIOODkeODqeODoeODvOOCv+OBruWumue+qQogICAgZG91YmxlIFIgPSAzMDAwLjA7ICAvLyDmirXmipcgKOOCquODvOODoCkKICAgIGRvdWJsZSBMID0gMC4wMDE7ICAgLy8g44Kk44Oz44OA44Kv44K/44Oz44K5ICjjg5jjg7Pjg6rjg7wpCiAgICBkb3VibGUgVl9FID0gNS4wOyAgIC8vIOmbu+a6kOmbu+WcpyAo44Oc44Or44OIKQogICAgZG91YmxlIHRpbWUsIEksIHRhdTsKICAgIGludCBzdGVwcyA9IDEwOyAgICAvLyDoqIjnrpfjgrnjg4bjg4Pjg5fmlbDjgpIxMOOBq+WItumZkAogICAgZG91YmxlIHRfbWF4ID0gMC4wMDE7IC8vIOioiOeul+OBmeOCi+acgOWkp+aZgumWkyAo56eSKQogICAgaW50IGk7ICAvLyDjg6vjg7zjg5flpInmlbAKCiAgICAvLyDmmYLlrprmlbAgz4QgPSBMIC8gUgogICAgdGF1ID0gTCAvIFI7CgogICAgLy8g5pmC6ZaT5aSJ5YyW44Gr5Ly044GG6Zu75rWBIEkodCkg44KS6KiI566XCiAgICBwcmludGYoIlRpbWUocylcdEN1cnJlbnQoQSlcbiIpOwogICAgZm9yIChpID0gMDsgaSA8PSBzdGVwczsgaSsrKSB7CiAgICAgICAgdGltZSA9IHRfbWF4ICogaSAvIHN0ZXBzOwogICAgICAgIEkgPSAoVl9FIC8gUikgKiAoMSAtIGV4cCgtdGltZSAvIHRhdSkpOwogICAgICAgIHByaW50ZigiJWZcdCVmXG4iLCB0aW1lLCBJKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=