How to use matlab to solve equation

How to use matlab to solve equation

1. Preface

As one of the three major mathematical software, Matlab is the best in numerical calculation. Solving equations is the most basic and common problem in engineering study and engineering calculation. It is very important to master the method of solving equations with modern tools to improve our engineering literacy. Therefore, this paper will introduce the method of solving equations in MATLAB.

2. Usage

solving process

2.1 – indicated variables

Tell the computer the variables contained in the equation, including parameters and unknown variables. For example, the equation to be solved is: obviously, there are symbolic variables a, B, C and X in the equation, so the writing method of this step is:

syms a b c x  

 

2.2 specify equations, unknowns and constraints (not required)

If there is more than one equation,

eqns put it in [] and separate it with a comma. For example:
vars unknowns to be solved
Names value (not required) Names: “return conditions” returns the general solution with parameters. ” If ‘true’ is returned and ‘false’ is not, a special solution is given;
Name: ‘ignoreanalytical constraints’ is the simplest form of the solution given. ‘true ‘is yes and’ false ‘is no
Name:’ principalvalue ‘only gives one solution. False is to return all solutions, true is to return only one solution;
Name: ‘real’ only returns real solutions

2.3 obtain the solution of the equation

If there are multiple functions, the solution is stored as a structure.

 

3. Specific examples

3.1 = general solution of sin (x) = 1

 

Specific code:

syms x  [x,params,conds]=solve(sin(x)==1,’ReturnConditions’, true) 

 

result

solx =pi/2+2*pi*k  params =k  conds =in(k,’integer’)

 

It can be seen that the general solution of the equation is as follows:

 

3.2 solve the following equation:

code:

syms a b c y x [x,y]=solve([a*x^2+b*y+c==0,a*x+2*y==4],[x,y])

 

result:

x =  ((a*b)/4-(-(a*(- a*b^2+32*b +16*c))/16)^(1/2))/a  ((a*b)/4+(-(a*(- a*b^2+32*b +16*c))/16)^(1/2))/a   y =  (-(a*(- a*b^2+32*b +16*c))/16)^(1/2)/2-(a*b)/8+2  2-(-(a*(- a*b^2+32*b +16*c))/16)^(1/2)/2-(a*b)/8

 

Namely:

Read More: