While loop will not stop running?
Afficher commentaires plus anciens
I have this code to develop the partial sum of (1/k^2). However, when I run the code, the while loop does not stop. Any help with this problem?
function [sum1,error,steps] = psum(tol)
k=1;
sum1=1/(k).^2;
answer=(pi.^2)/6;
error=abs(answer-sum1);
while error>tol
k=1/(k+1)^2;
term=sum1+(1/(k).^2);
sum1=sum1+term
error=abs(answer-sum1)
end
steps=k
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!