beginner: writing a function to caculate sum

3 visualizaciones (últimos 30 días)
Lola Rapoport
Lola Rapoport el 4 de Abr. de 2018
Editada: Lola Rapoport el 4 de Abr. de 2018
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.

Respuestas (1)

Birdman
Birdman el 4 de Abr. de 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)

Community Treasure Hunt

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

Start Hunting!

Translated by