having trouble with for loops
1 次查看(过去 30 天)
显示 更早的评论
Having Trouble...
'Sum of N^2 with N = 1 to 1,000 using a for loop'
0 个评论
采纳的回答
更多回答(2 个)
Roger Stafford
2014-2-13
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);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!