Matrix Multiplication with large vectors

조회 수: 7 (최근 30일)
amberly hadden
amberly hadden 2015년 5월 11일
댓글: Walter Roberson 2015년 5월 15일
Hi,
If I have following problem how can I formulate it in matlab
A=
1 3
2 4
b=
xi
yi
where xi and yi are column vectors with lets say 100 values in each how can I input this problem in Matlab by using following formula
[z1 = A*b
z2]
Please note I have very large martix with vectors xi and yi and I want out put two matrices z1 and z2
Thanks in advance, jay
thanks
  댓글 수: 3
amberly hadden
amberly hadden 2015년 5월 11일
편집: Walter Roberson 2015년 5월 11일
Thanks walter,
So here is the thing
zi = [1 2; 3 4]*[xi;yi]
so z1 = 1*xi+2*yi
z2 = 3*xi+4*yi
coz z1 and z2 are two vectors of same size as xi and yi respectively.
Thanks very much for your guidence
Walter Roberson
Walter Roberson 2015년 5월 11일
There seems to be some confusion about whether xi and yi are row vectors or column vectors. You said column vectors before, but [xi;yi] would create a single column vector of the two combined, with [xi,yi] producing two columns from two column vectors.

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

채택된 답변

Walter Roberson
Walter Roberson 2015년 5월 15일
T = arrayfun(@(x,y) A*[x;y], xi, yi, 'Uniform', 0);
z1z2 = vertcat(T{:});
z1 = z1z2(:,1);
z2 = z1z2(:,2);
However, this formulation of the code would not be efficient if you had a small A and long vectors. In your actual situation, what size() is your A ?
  댓글 수: 2
amberly hadden
amberly hadden 2015년 5월 15일
thanks, Walter apreciated
Walter Roberson
Walter Roberson 2015년 5월 15일
In the case of A being 2 x 2, it is faster just to write out the values
z1 = A(1,1) * xi + A(2,1) * yi;
z2 = A(1,2) * xi + A(2,2) * yi;

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

추가 답변 (1개)

Thorsten
Thorsten 2015년 5월 12일
편집: Thorsten 2015년 5월 12일
A = [1 2; 3 4];
xi = 10;
yi = 20;
x = [xi; yi];
z1 = A(1,:)*x;
z2 = A(2,:)*x;
or
z = A*x;
z1 = z(1);
z2 = z(2);
  댓글 수: 1
amberly hadden
amberly hadden 2015년 5월 15일
편집: Walter Roberson 2015년 5월 15일
Sorry I was away so could not follow up...
[z1
z2] = [1 2
3 4]*[xi
yi] xi = x1,x2,x3....x100 yi = y1,y2,y3..y100
2*2 matrix need to multiply by column vector (one in a sense but infect data has two of them) like
[a
b]

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

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by