beginner: writing a function to caculate sum

조회 수: 3 (최근 30일)
Lola Rapoport
Lola Rapoport 2018년 4월 4일
편집: Lola Rapoport 2018년 4월 4일
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.

답변 (1개)

Birdman
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)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by