why the fourier series coefficient answer in matlab different compare to my manually calculation

8 ビュー (過去 30 日間)
i was use matlab to slove the fourier coefficient, why the answer come out different compare to my manually caculation(1/pi)*((-cos(0)/n)+(cos(n*-pi)/n^2)+(cos(n*pi)/n^2)-(cos(0)/n^2)).
sin pi*n should be get zero right?
syms n t pi
f1=(-t)
f2=(t)
a0=(1/(2*pi))*(int(f1,t,-pi,0)+int(f2,t,0,pi))
an1=int(f1*cos(n*t),t,-pi,0);
a1=subs(an1,sin(n*pi),0);
an2=int(f2*cos(n*t),t,0,pi);
a2=subs(an2,sin(n*pi),0);
an=(1/pi)*((an1+an2))
-(2*(2*sin((pi*n)/2)^2 - n*pi*sin(pi*n)))/(n^2*pi) (matlab answer)
  2 件のコメント
John D'Errico
John D'Errico 2020 年 4 月 5 日
Is n an integer? Given your statement that sin(n*pi) should be an integer, can we infer that n is an integer?
Should a computer know that, without being told? I see only that n is some symbolic parameter, in terms of what you tell MATLAB.

サインインしてコメントする。

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 5 日
編集済み: Ameer Hamza 2020 年 4 月 5 日
As pointed by John in his comment. You need to specify that the symbolic variable n is integer explicitly. You assume() to inform MATLAB that n is an integer and then use simplify() to apply the assumption. Also, don't directly define pi as a symbolic variable. pi is built-in constant.
syms n t
PI = sym(pi);
f1=(-t);
f2=(t);
a0=(1/(2*PI))*(int(f1,t,-PI,0)+int(f2,t,0,PI));
an1=int(f1*cos(n*t),t,-PI,0);
a1=subs(an1,sin(n*PI),0);
an2=int(f2*cos(n*t),t,0,PI);
a2=subs(an2,sin(n*PI),0);
an = (1/PI)*((an1+an2));
assume(n/2, 'integer');
simplify(an)
assume((n+1)/2, 'integer');
simplify(an)
Result
ans =
0
ans =
-4/(n^2*pi)
  6 件のコメント
jason tan
jason tan 2020 年 4 月 5 日
ya,mistake on that.
Tq Ameer Hamza

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by