solving linear systems of equations
62 views (last 30 days)
Show older comments
i want to solve the following linear systems:
a)
2y+3x-7z=6
3z+5x-y=10
-4x+y+z=4
b)
2y+3x-7z=6
3z+5x-y=10
-4y-6x+14z=-12
i wrote the following code:
clc
clear
A=[3 2 -7; 5 -1 3; -4 1 1]
B=[6;10;4]
%Ax=B, therefore x=B/A
x=B./A
x=linsolve(A,B)
C=[3 2 -7;5 -1 3;-6 -4 14]
D=[6;10;-12]
%if Cx=D, therefore x=D/C
x=D./C
x=linsolve(C,D)
and it works for the first but not the second, this comes up in the command window anyone know why?
Warning: Matrix is singular to working precision.
> In q8_2 (line 15)
x =
NaN
NaN
NaN
1 Comment
Jan
on 28 Jan 2019
Edited: Jan
on 28 Jan 2019
@Chloe St John: You have removed 3 of your questions alraedy. This behavior is disliked in the forum, because you do not want to participate in the community but only to consume the help for free. In case that you try to remove your question again, here is a copy:
i want to solve the following linear systems:
a) 2y+3x-7z=6
3z+5x-y=10
-4x+y+z=4
b) 2y+3x-7z=6
3z+5x-y=10
-4y-6x+14z=-12
i wrote the following code:
clc
clear
A=[3 2 -7; 5 -1 3; -4 1 1]
B=[6;10;4]
%Ax=B, therefore x=B/A
x=B./A
x=linsolve(A,B)
C=[3 2 -7;5 -1 3;-6 -4 14]
D=[6;10;-12]
%if Cx=D, therefore x=D/C
x=D./C
x=linsolve(C,D)
and it works for the first but not the second, this comes up in the command window anyone know why?
Warning: Matrix is singular to working precision.
> In q8_2 (line 15)
x =
NaN
NaN
NaN
Answers (4)
Torsten
on 28 Jan 2019
Edited: Torsten
on 28 Jan 2019
The matrix C is singular.
Check whether the linear system C*x=D is solvable at all (Remember the rank condition rank (C ) = rank (C,D)).
If it is solvable, you can use x=pinv(C )*D to get a solution.
Note that x=B./A and x=D./C is wrong in your notation ; it must read x=A\B and x=C\D.
Best wishes
Torsten.
0 Comments
Annapoorna Nyamagoudra
on 12 Jan 2021
2x+3y−z+2w=7;
x+y+z+w=2;
x+y+3z−2w=−6;
x+2y+z−w=-2
1 Comment
Walter Roberson
on 12 Jan 2021
A = [2 3 -1 2
1 1 1 1
1 1 3 -2
1 2 1 -1]
b = [7; 2; -6; -2]
A\b
Sumith M
on 6 Aug 2022
x-y=2
x+y=4
2x+y=8
1 Comment
Walter Roberson
on 6 Aug 2022
That system is inconsistent.
Add the first two equations. You get 2*x=6 so x=3. Add the first and last equations. You get 3*x=10 which would require that 3*3=10 which fails
See Also
Categories
Find more on Graphics Performance 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!