필터 지우기
필터 지우기

Hi,. I need support in doing a double summation in MATLAB. Thank you.

조회 수: 1 (최근 30일)
hani daniel
hani daniel 2017년 4월 28일
댓글: Adam 2017년 4월 28일
Hi,
I need to do the following double summation ∑(i=0,2)∑(j=0,3)〖(2i+3j)〗in a MATLAB program. The answer should be 78. Thank you.
HD

채택된 답변

hani daniel
hani daniel 2017년 4월 28일
Hi Star Strider,
Thank you for your answer.
Regards
HD
  댓글 수: 1
Adam
Adam 2017년 4월 28일
Please just accept the answer you are happy with. Don't add your own answer to just say which answer works and then accept that! You can add comments to people's answers.

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

추가 답변 (3개)

Stephen23
Stephen23 2017년 4월 28일
>> M = bsxfun(@plus,2*(0:2),3*(0:3).');
>> sum(M(:))
ans = 78

hani daniel
hani daniel 2017년 4월 28일
Hi Stephen,
Thank you for your answer, it is correct. However, as a beginner at MATLAM, I do not understand the bsxfun command. I was expecting to use a for loop type of solution. Please let me know of alternatives. Thank you.
Regards
HD

Star Strider
Star Strider 2017년 4월 28일
There are likely several ways to code this (I assume this is a coding exercise, since the correct answer is provided).
This is one approach:
i = 0:2;
j = 0:3;
[I,J] = meshgrid(i, j);
f = @(i,j) 2*i + 3*j; % Anonymous Function
fmtx = f(I,J);
Answer = sum(fmtx(:))
I am not documenting it, leaving it for you to understand how it works.
  댓글 수: 2
Star Strider
Star Strider 2017년 4월 28일
hani daniel’s Answer is copied here:
Hi Star Strider,
Thank you for your answer.
Regards
HD

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

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by