Analytical solution:
- Solving equations:
[x1,x2,x3,...]=solve(‘eq1’,'eq2','eq3',......,'x1','x2','x3','....')
S=solve(‘eq1’,'eq2','eq3',......,'x1','x2','x3','....')
- The first method requires the order of x1, x2, and x3 in the brackets of the solve (consistent with the previous []), and the second has no requirements. eq is an equation, not an expression.
- It is best to put quotation marks, or not to put quotation marks, but you must use sym, syms and other settings and pre-defined symbols in advance.
- Solve the differential equation:
dsolve(‘eq1’,'eq2',....)
Same as above
Numerical Solution
Generally use ode45 (@fun,tspan,y0)
1. Write the sub-functions, use the form of a matrix to represent the differential equations, and the original problem must be converted into n first-order differential equations.
2.y0 is generally a (n*1) vector, and tspan is generally a binary vector
2. You can also use function handles (anonymous functions)
example:
For y'=2t, solve the differential equation
tspan = [0,5]; y0 = 0; [t,y] = ode45(@(t,y) 2*t, tspan, y0);%Method of using function handle