前提・実現したいこと
上図のような振幅スペクトルのグラフを指数関数(e^iみたいな)で作りたいです。
横軸が周波数、縦軸が振幅(の絶対値)です。
三角関数で式を表記した時はうまくいったのですが、指数関数で表記すると縦軸である振幅の絶対値(Fx[1])が0にしかならず、困っています。
式以外はすべて同じソースコードです。
うまくいったソースコード
C言語
1#include <stdio.h> 2#include <math.h> 3#include <complex.h> 4 5#define aM (10.0) //時刻tにおける加速度a_max[m/s/s] 6#define T (0.0332) //終端時刻[s]● 7 8int main(void) 9{ 10 double w = 0.0, dw = 1.0; //角周波数 11 12 do { 13 double _Complex Fx[2]; 14 double f; 15 16 f = w/(2.0*M_PI); //周波数 17 Fx[0] = aM*(cos(w*T) - I*sin(w*T) - 1.0)/(-I*w); //加速度のフーリエ変換 18 Fx[1] = cabs(Fx[0]); //Fx[0]の絶対値(振幅の絶対値) 19 20 printf("%g %g+%gi\n", f, creal(Fx[1]), cimag(Fx[1])); 21 22 w += dw; 23 } while (w <= 2000.0); 24}
うまくいかなかったソースコード
C言語
1#include <stdio.h> 2#include <math.h> 3#include <complex.h> 4 5#define aM (10.0) //時刻tにおける加速度a_max[m/s/s] 6#define T (0.0332) //終端時刻[s]● 7 8int main(void) 9{ 10 double w = 0.0, dw = 1.0; //角周波数 11 12 do { 13 double _Complex Fx[2]; 14 double f; 15 16 f = w/(2.0*M_PI); 17 Fx[0] = aM*(exp(-I*w*T) - 1.0)/(-I*w); 18 Fx[1] = cabs(Fx[0]); 19 20 printf("%g %g+%gi\n", f, creal(Fx[1]), cimag(Fx[1])); 21 22 w += dw; 23 } while (w <= 2000.0); 24}
回答1件
あなたの回答
tips
プレビュー