Displaying output from a summation.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Edward Steen
am 5 Okt. 2015
Kommentiert: Edward Steen
am 5 Okt. 2015
I'm trying to find partial sums of s=1/k^2 where k= multiples of 400. I'm using a "for" statement and want to have the script output the values at those multiples. At this point, I can only get it to output the final value. I want it to output the sums for k=400, 800, 1200, ... Also, I would like the output for the error for the actual sum.
Code is below.
format long
s=0;
for n=1:13
k=400;
end
for i=1:n*k
s=s+1/i^2;
y=abs(s-(pi^2/6));
end
disp([' Error', ' s_n'])
disp([y,s])
Thanks.
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!