MATLAB: Matrix with vectors: multiplication and generation issue

matrix multiplication using for loopmatrix with vectors

Hi I have confusion with the following problem.
Let there is matrix A=[ sin(i) 0; 0 cos(i)] where i is vector of 100 elements , B= [ a b; c d] and C=[e ; g].
Now I have to multiply B*A*C. Can someone help? I am confuse either I am suppose to use for loop or what?

Best Answer

Yes you could do this with a loop, for example, with just some arbitrary set values for i, a, b, c, d, e, g to illustrate
theta = linspace(0,2*pi,100);
a = 10;
b = 3;
c = 20;
d = 40;
e = 2;
g = 25;
% assign constant matrices
B = [a b;c d];
C = [e;g];
% preallocate array Z to hold result (one column for each value of theta)
numTheta = length(theta); % number of elements in theta
Z = zeros(2,numTheta)
for i = 1:numTheta
A = [sin(theta(i)) 0;0 cos(theta(i))];
Z(:,i) = B*A*C
end