Summation of Infinity Terms

조회 수: 54 (최근 30일)
Rewida Hassan
Rewida Hassan 2019년 12월 8일
답변: dpb 2019년 12월 9일
S = 0;
tol = eps;
term = inf;
n = 0;
while abs(term) > tol
term = exp(x*log10(n));
S = S + term;
n = n + 1;
end
It try by this way but I don't know what is wrong
لا
  댓글 수: 9
dpb
dpb 2019년 12월 9일
편집: dpb 2019년 12월 9일
I missed one thing in my first look...look at the summation limits carefully in the definition and what you initialized n as.
Actually, missed the biggie by not paying attention...dunno where you got the expression you're evaluatiing, but that isn't the expression in the assignment at all...
Again, you do need to define x (>1 for series to converge)
Rewida Hassan
Rewida Hassan 2019년 12월 9일
편집: dpb 2019년 12월 9일
S = 0;
tol = eps;
term = inf;
n = 1;
If (x<1)
'not valid starting points enter another points'
end
while abs(term) > tol
term = (1/power (n , x));
S = S + term;
n = n + 1;
end

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

채택된 답변

David Hill
David Hill 2019년 12월 8일
You need to create a function. The easiest is to use the existing function. It doesn't sound like your instructions prevent this.
function z = myzeta(x)
z=zeta(x);
end
Alternatively, it is easy to determine the stopping point but floating point inaccuracies will affect the result.
function z = myzeta(x)
n=ceil((1/eps)^(1/x));
z=sum((1:n).^(-x));
end

추가 답변 (1개)

dpb
dpb 2019년 12월 9일
S = 0;
tol = eps;
term = inf;
n = 1;
If (x<1)
'not valid starting points enter another points'
end
while abs(term) > tol
term = (1/power (n , x));
S = S + term;
n = n + 1;
end
Is not bad start for learner...I used similar with few changes and got answers that match those looked up...
S = 0;
tol = 1E-7; % run quicker; approx single precision accuracy eps;
term = bigvalue; % use finite values instead of inf
n = 1;
if (x<=1), error('not valid x--enter another points >1'), end
while abs(term) > tol
term = (1/power (n , x));
S = S + term;
n = n + 1;
end

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by