Simple MATLAB sum question.

조회 수: 1 (최근 30일)
Myles Baker
Myles Baker 2011년 1월 21일
I am running a very old MATLAB 6.1. Anyways, I am have:
Ax=b
A=[a11 a12 a13;
a21 a22 a23;
a31 a32 a33]
x=[x1;
x2;
x3]
I want to write a MATLAB program that simply calculates:
b1=x1*a11+x1*a12+x1*a13
...
And the current code I have:
b(1:n,1)=zeros(n,1);
for j=1:n
b(j,1)=x(j,1)*A(1,j)
end
Does not work. I have tried adding a nested for loop. No luck. I have tried the sum command. No luck.
Basically I want to do:
sum(A(1,:)+A(2,:)+...+A(j,:))
In a controlled loop sequence. I have tried:
for j=1:n
sum(A(j,:))
end

답변 (2개)

Walter Roberson
Walter Roberson 2011년 1월 21일
Have you tried sum(A(1:j,:),2) ? I am referring to your "Basically I want to do" portion of your question, which otherwise appears to be incomplete in that it does not have the multiplication by b .
Does your version of Matlab not support matrix multiplication,
b = A*x;

Matt Fig
Matt Fig 2011년 1월 21일
Is this what you are after?
b = zeros(3,1);
for ii = 1:3
for jj = 1:3
b(ii)= b(ii) + A(ii,jj)*x(jj);
end
end

카테고리

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