Jump to content
Dung the most handsome man

Calculate the sum of a series

Recommended Posts

Hi Dung,

you can get more accurate result by having a tolerance condition inside a while loop. something like below:

 

%%

clc, clear
sum = 0;
sum_before = realmax;
tol = 1e-12;  % tolerance value
i = 0;

while (abs(sum_before - sum) >= tol) 
    i= i+ 1;
    sum_before = sum;
    sum = sum + 1/(i^2);        
end 

%%

Hope this helps

 

Thanks,

Manoj kandukuri
 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×