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

23 ビュー (過去 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 Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by