필터 지우기
필터 지우기

How to form an array of sums?

조회 수: 2 (최근 30일)
Yuval
Yuval 2013년 10월 19일
댓글: Anthony 2013년 10월 20일
Hi, I am asked to evaluate the following sum S=Sigma(n=0 to N) x^n/n! (namely, e^x as n->Inf) for N=10:10:100 and x=10, so that every element S(i) is a partial sum which approximates function e^x with different accuracy. Below is my code, which doesn't work:
x=10; N=10:10:100; S=symsum(x^n/sym('n!'), n, 0, N)
Would anyone please tell me where I am going wrong and how it may be corrected? I'd appreciate some guidance.

답변 (1개)

Anthony
Anthony 2013년 10월 19일
편집: Anthony 2013년 10월 19일
syms n;
x=10;
N=100;
% N cannot be a vector (if you want N=10:10:100, use a loop instead.)
S=double(symsum(x^n/sym('n!'), n, 0, N))
  댓글 수: 2
Yuval
Yuval 2013년 10월 19일
Hi Anthony, Thank you very much for your reply. I am now trying the following, albeit, alas, it still does not quite work:
x=10; N=10; i=0; while (N<=100), S(i)=double(symsum(x^n/sym('n!'), n, 0, N)); i=i+1; N=N+10; end
Could you please advise?
Anthony
Anthony 2013년 10월 20일
편집: Anthony 2013년 10월 20일
add 'syms n;', and initialize i=1 instead of 0.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numbers and Precision에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by