How to compute the sum of the squares of all integers from 2 to 20 using for-loop?
16 次查看(过去 30 天)
显示 更早的评论
Hey guys i am very new to MATLAB and i am currently in a class and need help with homework! thank you in advance!
回答(1 个)
Prasanna Venkateshan
2020-7-7
编辑:Prasanna Venkateshan
2020-7-7
The variable sum contains your output
sum=0; for i=2:20 sum=sum+i^2; end disp(sum)
1 个评论
Image Analyst
2020-7-7
Yes, but sum() is a built-in function that you should not destroy by calling your variable sum. Choose another name, like sumOfSquares or something.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!