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

조회 수: 16 (최근 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