Simple MATLAB sum question.
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (2 件)
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;
0 件のコメント
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
0 件のコメント
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!