Why is the inv function not working in this code (simple)
10 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
James Tursa
on 1 Oct 2019
Edited: James Tursa
on 1 Oct 2019
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.
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!