I multiply 3x3 and 3x1 matrix and the end result is 3x3 instead of 3x1. What's wrong with the code.?

17 次查看(过去 30 天)
k1=[1 -1;-1 1]; x=3 %Number of Elements K=zeros(x+1,x+1); F=zeros(x+1, 1); U=zeros(x, 1); for i=1:x k=k1*AEL(i); F(i+1,1)=F(i+1,1)+(1000*500/x); K(i:i+1, i:i+1)=K(i:i+1, i:i+1)+k; end K2=K(2:x+1, 2:x+1); F2=F(2:x+1, 1); Kinv=inv(K2); U=Kinv.*F2

回答(1 个)

Roger Stafford
Roger Stafford 2017-3-5
You have used .* instead of *, which is element-by-element, so matlab automatically expands F2 as: repmat(F2,1,3) and then performs the 3 by 3 multiplication element-wise with another 3 by 3 to get a 3 by 3 result. Use just * for matrix multiplication.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by