How to solve equation with MatLab?

 How to solve equation with MatLab?


It is quite simple.

Way1:
using solve method.

Step1:
Declare symbolic variable.

Step2:
Declare the equation.

Step3:
using solve method. Then you will get a struct field.

 I wanna solve the system of equations.
I write the following code.

%clear workspace 

clear 

%clear command window 

clc 

  

%way1: 

%solve it 

syms x y z; 

equ1=3*x-3*y+z==2 

equ2=x-y+z==1 

equ3=7*x+5*y-z==-5 

  

%find a solution of equation 

sol=solve([equ1,equ2,equ3],[x,y,z]) 

%ans 

x=sol.x 

y=sol.y 

z=sol.z 


[NOTE]


syms must be seperated in space instead of ','.

such as syms x,y,z; is not acceptable.



Want to learning a lot?

I recommend you to take a look at them.

Solve System of Linear Equations - MATLAB & Simulink (mathworks.com)

or

How to Solve Simultaneous Equations in MatLAB Using linsolve and solve - YouTube

Comments

Popular posts from this blog

diagonal matrix--diag

a convenient type to record lots of value in MatLab -- cell matrix

Anonymous Function in MatLab