Solving equations and equations with MATLAB

1. Solve function

① Numerical solution of single equation

syms x;

x0 = double(solve(x +2 – exp(x),x));

Find the solution of X + 2 = exp (x), and the result is shown in double

In use, you can also write x + 2 = = exp (x), note that ‘= =’

In addition, if there are multiple solutions, the function returns only one solution

② Solving the equation with signed variables

syms x a b c;

x0 = solve(a*x^2+b*x+c,x);

Two solutions can be obtained

③ Solving equations

syms x y z;

e1 = 2*x – y +z;

e2 = x + y – 6;

e3 = z^2 +2*y;

[x0,y0,z0] = solve(e1,e2,e3,x,y,z);

double([x0,y0,z0])

Can return multiple solutions, note that can not directly solve double conversion

2. Vpasolve function

Only one solution can be returned to solve the equation in a certain range

syms x;

double(vpasolve(x +2 – exp(x),x,[-2,2]))

The solution near a point can also be obtained

double(vpasolve(x +2 – exp(x),x,1))

The premise is that this’ nearby point ‘cannot deviate too much from the solution

To find out all the solutions, we can first draw a graph and find out the approximate interval or adjacent points of each solution

Read More: