I multiply 3x3 and 3x1 matrix and the end result is 3x3 instead of 3x1. What's wrong with the code.?
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
Antworten (1)
Roger Stafford
am 5 Mär. 2017
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.
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!