why this code involving symsum doesn't work

2 ビュー (過去 30 日間)
Qiao Wei Ting
Qiao Wei Ting 2020 年 5 月 19 日
コメント済み: Qiao Wei Ting 2020 年 5 月 21 日
I am supposed to create a function that can compute the formula in the attachment. But the the variables x and n in my_sin(x,n) don't sync with the one in symsum.
it will be very helpful if someone can tell me where is wrong.
function y = my_sin(x,n)
syms x n
outputArg1 = x;
outputArg2 = n;
y=symsum([-1^n]*[[x^2*n]+1]*[1/factorial(2*n+1)],n,0,n);
end
  1 件のコメント
Qiao Wei Ting
Qiao Wei Ting 2020 年 5 月 19 日
my_sin(1, 2)
ans =
- (8178130767479*x^2)/44460928512000 - 603180793741/513257472000
the answer appears to be like this.

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

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 5 月 19 日
Variable of summation is 'i'. Try this code
function y = my_sin(x,n)
syms I
y=symsum((-1^I)*x^(2*I+1)/factorial(2*I+1),I,0,n);
end
Run it like this
>> my_sin(1, 2)
ans =
-47/40
  1 件のコメント
Qiao Wei Ting
Qiao Wei Ting 2020 年 5 月 21 日
Got it! thanks a lot

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by