beginner: writing a function to caculate sum
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Birdman
on 4 Apr 2018
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 Comments
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!