Why is the inv function not working in this code (simple)

10 ビュー (過去 30 日間)
Delta
Delta 2019 年 10 月 1 日
コメント済み: Delta 2019 年 10 月 1 日
m=[cos(-90*pi/180)-cos(30*pi/180) 1;cos(-135*pi/180)-cos(45*pi/180) 1; cos(-180*pi/180)-cos(70*pi/180) 1];
r=[cos(120*pi/180); cos(180*pi/180); cos(250*pi/180)];
k=inv(m)*r;a(1)= 1/k(1); a(3)=1/k(2);
t1=1/k(1)^2;t2=1/k(2)^2;t3=2*k(3)/k(1)*k(2));a(2)=(t1+t2+1-t3)^.5;
thank you!

採用された回答

James Tursa
James Tursa 2019 年 10 月 1 日
編集済み: James Tursa 2019 年 10 月 1 日
Best to put commas in your matrix difinition so that the parser doesn't inadvertently combine things that you didn't want. E.g., (assuming you wanted a 3x3 instead of a 3x2 matrix result)
>> m=[cos(-90*pi/180)-cos(30*pi/180) 1;cos(-135*pi/180)-cos(45*pi/180) 1; cos(-180*pi/180)-cos(70*pi/180) 1]
m =
-0.8660 1.0000
-1.4142 1.0000
-1.3420 1.0000
>> m=[cos(-90*pi/180),-cos(30*pi/180), 1;cos(-135*pi/180),-cos(45*pi/180), 1; cos(-180*pi/180),-cos(70*pi/180), 1]
m =
0.0000 -0.8660 1.0000
-0.7071 -0.7071 1.0000
-1.0000 -0.3420 1.0000
That being said, this operation with inv( )
>> k=inv(m)*r
k =
1.3568
2.8907
2.0035
is better performed using the backslash operator:
>> k=m\r
k =
1.3568
2.8907
2.0035
You rarely need to use the inv( ) function in MATLAB.
  1 件のコメント
Delta
Delta 2019 年 10 月 1 日
thank you thats great!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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