Posted By:
24 Mar, 2013 12:57 pm PDT

Solving Linear set of equations in Matlab

I have three equations in variables x, y, z. How can I find the solution for the variables, if the solution is unique.

For example:

x-y+z=10
x+y+2z=15
x+3y-z = 5


The solution to above set of equations is x= 6.8750, y= 0.6250, z= 3.7500.

Also, what if there are more than one solution? how can I know that and how to find all the solutions?
For example:

x-y+z=10
x+y+z=15
x+3y+z = 5


there are many solutions to above equations.

Attachment:None


 
% One Solution--------
% ----------------------
% x-y+z=10
% x+y+2z=15
% x+3y-z = 5
%to solve aboove set of equations
A = [1 -1 1;
    1 1 2;
    1 3 -1];
b = [10;15;5];
only_one_solution = A\b;
% or only_one_solution = inv(A)*b;


% No Solutions--------
% ----------------------
% x-y+z=10
% x+y+z=15
% x+3y+z = 5
A=[1 -1 1;
    1 1 1;
    1 3 1];
b = [10;15;5];

no_solution = A\b;
% Many Solutions--------
% ----------------------
% x-y+z=10
% x+y+z=15
A=[1 -1 1;
    1 1 1];
b = [10;15];


one_solution = A\b;
alpha =1;
Many_solutions =one_solution+alpha*null(A);




 Please watch video for details

Was it useful?  




Please login to reply to this problem.