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

8 ビュー (過去 30 日間)
Delta 2019 年 10 月 1 日
Commented: 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!

#### 0 件のコメント

サインイン to comment.

### 採用された回答

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 2019 年 10 月 1 日
thank you thats great!

サインイン to comment.