#include <stdio.h>
#include <math.h>
#define R 3000.0 // 抵抗値 3 kΩ
#define L 0.001 // インダクタンス 1 mH
#define V 5.0 // 入力電圧 5V
#define TIME_STEP 0.0001 // 時間の刻み幅
#define MAX_TIME 0.01 // 最大計算時間
double calculate_current(double t) {
return (V
/ R
) * (1 - exp(-R
* t
/ L
)); }
int main() {
for (double t = 0; t <= MAX_TIME; t += TIME_STEP) {
double current = calculate_current(t);
printf("%.6f\t%.6f\n", t
, current
); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CgojZGVmaW5lIFIgMzAwMC4wICAgICAgLy8g5oq15oqX5YCkIDMga86pCiNkZWZpbmUgTCAwLjAwMSAgICAgICAvLyDjgqTjg7Pjg4Djgq/jgr/jg7PjgrkgMSBtSAojZGVmaW5lIFYgNS4wICAgICAgICAgLy8g5YWl5Yqb6Zu75ZynIDVWCiNkZWZpbmUgVElNRV9TVEVQIDAuMDAwMSAgLy8g5pmC6ZaT44Gu5Yi744G/5bmFCiNkZWZpbmUgTUFYX1RJTUUgMC4wMSAgICAgLy8g5pyA5aSn6KiI566X5pmC6ZaTCgpkb3VibGUgY2FsY3VsYXRlX2N1cnJlbnQoZG91YmxlIHQpIHsKICAgIHJldHVybiAoViAvIFIpICogKDEgLSBleHAoLVIgKiB0IC8gTCkpOwp9CgppbnQgbWFpbigpIHsKICAgIHByaW50Zigi5pmC6ZaTKHMpXHTpm7vmtYEoQSlcbiIpOwogICAgZm9yIChkb3VibGUgdCA9IDA7IHQgPD0gTUFYX1RJTUU7IHQgKz0gVElNRV9TVEVQKSB7CiAgICAgICAgZG91YmxlIGN1cnJlbnQgPSBjYWxjdWxhdGVfY3VycmVudCh0KTsKICAgICAgICBwcmludGYoIiUuNmZcdCUuNmZcbiIsIHQsIGN1cnJlbnQpOwogICAgfQogICAgcmV0dXJuIDA7Cn0K