Reputation: 403
I have 3 vectors and I want to multiply each of them with it's transpose for example I have A1=[-1 1 -1 1] and I want to find At1=A1'*A1. However, I have several vectors and will be adding more than 3 vectors. So, I constructed a for loop to do this for me however, it is not working and I don't know why. Below is my code:
A(1)=[-1 1 -1 1];
A(2)=[1 1 1 -1];
A(3)=[-1 -1 -1 1];
for i=1:3
At(i)=A(i)'*A(i)
i=i+1
end
At=At1+At2+At3
Can someone help?
Upvotes: 0
Views: 45
Reputation: 253
You can achieve what you want like this:
A(1,:)=[-1 1 -1 1];
A(2,:)=[1 1 1 -1];
A(3,:)=[-1 -1 -1 1];
At = trace(A * A'); %sum of the A(i,:)*A(i,:)'
PS. don't do i=i+1 in your loop, it is done automatically for you.
Upvotes: 1