필터 지우기
필터 지우기

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

조회 수: 9 (최근 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 CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by