#include <stdio.h>
#include <math.h>
// 定数の設定
#define E 5.0 // 電源電圧 (V)
#define R 30.0 // 抵抗 (Ω)
#define L 0.003 // インダクタンス (H)
#define C 0.0000004 // キャパシタンス (F)
#define T_MAX 0.002 // シミュレーション終了時間 (s)
#define DT 0.00002 // 時間ステップ (s)
int main() {
double alpha, omega_squared, omega; // 定数
double t = 0.0; // 時間
double I_t; // 電流
// 定数計算
alpha = R / (2.0 * L);
omega_squared = (1.0 / (L * C)) - (alpha * alpha);
omega
= sqrt(omega_squared
);
// ヘッダを表示
// 時間ごとの電流を計算して出力
while (t <= T_MAX) {
I_t
= (E
/ (omega
* L
)) * exp(-alpha
* t
) * sin(omega
* t
); // 電流 I(t) を計算 printf("%.6f\t%.6f\n", t
, I_t
); t += DT; // 時間を更新
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CgovLyDlrprmlbDjga7oqK3lrpoKI2RlZmluZSBFIDUuMCAgICAgICAgICAvLyDpm7vmupDpm7vlnKcgKFYpCiNkZWZpbmUgUiAzMC4wICAgICAgICAgLy8g5oq15oqXICjOqSkKI2RlZmluZSBMIDAuMDAzICAgICAgICAvLyDjgqTjg7Pjg4Djgq/jgr/jg7PjgrkgKEgpCiNkZWZpbmUgQyAwLjAwMDAwMDQgICAgLy8g44Kt44Oj44OR44K344K/44Oz44K5IChGKQojZGVmaW5lIFRfTUFYIDAuMDAyICAgIC8vIOOCt+ODn+ODpeODrOODvOOCt+ODp+ODs+e1guS6huaZgumWkyAocykKI2RlZmluZSBEVCAwLjAwMDAyICAgICAvLyDmmYLplpPjgrnjg4bjg4Pjg5cgKHMpCgppbnQgbWFpbigpIHsKICAgIGRvdWJsZSBhbHBoYSwgb21lZ2Ffc3F1YXJlZCwgb21lZ2E7IC8vIOWumuaVsAogICAgZG91YmxlIHQgPSAwLjA7ICAgICAgICAgICAgICAgICAgICAgLy8g5pmC6ZaTCiAgICBkb3VibGUgSV90OyAgICAgICA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