How to compute the sum of the squares of all integers from 2 to 20 using for-loop?

13 ビュー (過去 30 日間)
Burak
Burak 2013 年 9 月 26 日
コメント済み: Image Analyst 2020 年 7 月 7 日
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
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
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 ExchangeGet Started with MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by