beginner: writing a function to caculate sum
3 ビュー (過去 30 日間)
古いコメントを表示
I'm stuck with the following task: writing a function to caculate:

When N is known.
I wrote this code and I don't know what is wrong with that:
N = input('enter N\n');
for i=1:N
F2=symsum(((sin(i))^2), i, 1, N);
disp (F2);
end
I would like for an explainaton.
0 件のコメント
回答 (1 件)
Birdman
2018 年 4 月 4 日
The purpose of using Symbolic Toolbox and symsum function in this case is to get rid of a for loop and do all the necessary stuff in just one line. Therefore for loop should be erased. The following code will do it for you:
syms f1(n) f2(n) i
N=3;
f1(n)=symsum(1/i,i,1,N)
f2(n)=symsum(sin(i)^2,i,1,N)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!