I multiply 3x3 and 3x1 matrix and the end result is 3x3 instead of 3x1. What's wrong with the code.?
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ibrahim Mahmood Shah
el 5 de Mzo. de 2017
Comentada: Ibrahim Mahmood Shah
el 5 de Mzo. de 2017
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
Respuestas (1)
Roger Stafford
el 5 de Mzo. de 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.
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!