Summation of Infinity Terms
Afficher commentaires plus anciens
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 commentaires
dpb
le 8 Déc 2019
Put the Q? in the space for it, not the title.
We don't solve homework without the poster showing what effort they've put into it first...
Rewida Hassan
le 8 Déc 2019
dpb
le 8 Déc 2019
Again, put the question in the space supplied for it (unless the submitter also can't edit the title once entered?)
Then use the code button to format the code legibly.
Then, what is the specific Matlab question?
dpb
le 8 Déc 2019
No, what is YOUR specific Matlab question regarding the homework problem? Where did you have trouble?
But, thank you for proper formatting...helps greatly for folks to be able to follow. :)
Rewida Hassan
le 8 Déc 2019
dpb
le 8 Déc 2019
For starters, x isn't defined...
You probably want to set the tolerance to something > eps for initial testing.
Other than that, looks ok to me; set breakpoint in the debugger and step through to see what happens as you iterate.
Rewida Hassan
le 8 Déc 2019
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
le 9 Déc 2019
Modifié(e) : dpb
le 9 Déc 2019
Réponse acceptée
Plus de réponses (1)
dpb
le 9 Déc 2019
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
Catégories
En savoir plus sur Functions dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!