Friday, March 13, 2009

Solving equation of three variables in Matlab

If we have the following equations :

8x-2y+5z=10
-2x+10y-3z=0
-5x-3y+10z=0

we can solve the equation in Matlab in the following way. Write simply in the command window :

A=[8 -2 5; -2 10 -3; -5 -3 10]; % a 3x3 matrix
b=[10;0;0]%a 3x1 matrix, be careful not to forget the two semicolons they mean break to the next row in matrix

temp=inv(A)*b % temp will be a 3x1 matrix and contains your answer :-)
x=temp(1)
y=temp(2)
z=temp(3)

No comments: