Compute the summation of all elements square of matrix

조회 수: 17 (최근 30일)
vishnuvardhan Reddy
vishnuvardhan Reddy 2020년 9월 4일
댓글: the cyclist 2020년 9월 4일
  댓글 수: 3
Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020년 9월 4일
you can use either
sum(a(:))
or
sum(sum(a))
the cyclist
the cyclist 2020년 9월 4일
In recent versions of MATLAB, one can also do
sum(a,'all')

댓글을 달려면 로그인하십시오.

답변 (2개)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020년 9월 4일
% simply use
sum(a(:))

the cyclist
the cyclist 2020년 9월 4일
This looks like homework.
In the future, please listen to James Tursa's advice, and post what you have tried, be specific about what you want to know, and don't simply post an image of your homework. That is simply not the way to learn, which I assume is your goal.
That being said, and since others have posted solutions, I'll point out that there is some poor English in that question, that makes it ambiguous. It says, "the summation of all the elements' square".
This could reasonably be taken to mean any of the following:
  • the matrix is a square, so just sum all the elements
  • square the matrix (i.e. A*A), then sum the elements
  • square each element individually, then take the sum of all of them
My best guess is the assignment is trying to get you to do the last one. Maybe with the other comments/answers here, you can figure it out.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by