Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 13 Feb. 2014

0 Stimmen

out = 1;
for ii = 2:1000
out = out + ii^2;
end

3 Kommentare

Joseph
Joseph am 13 Feb. 2014
SumN=0; % initializes N^2
for N=1:1000
SumN = SumN + N^2;
end
Still not giving me correct answer...Don't know what I'm doing wrong
Thomas
Thomas am 13 Feb. 2014
what answer do u expect?
Joseph
Joseph am 13 Feb. 2014
i got it thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Roger Stafford
Roger Stafford am 13 Feb. 2014

0 Stimmen

Here's a way to check your answer:
n = 1000;
s = n*(n+1)*(2*n+1)/6;
This gives you the same value as
s = sum((1:n).^2);
Alonso Mukendi Kalonji
Alonso Mukendi Kalonji am 29 Okt. 2022

0 Stimmen

a = 1;
n= 1000;
for i = 1: n
a = a+i^2
end
disp(a)

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by