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!