Symbolic Root Finding Approach
- Performing mathematics on symbols, NOT numbers
- The symbols math are performed using “symbolic variables”
- use sym or syms to create symbolic variables
就是利用sym来创建一个未知数x
1 | syms x |
或者
1 | x = sym('x'); |
同时用未知数去定义一个量,那个量也变为未知数
例如:1
y = x^2 - 2*x -8
Symbolic Root Finding: solve()
- Function ‘solve’ finds roots for equations
对于:y = x*sin(x) - x = 0
1 | syms x |
1 | syms x |
Solving Multiple Equations
- solve this equation using symbolic approach:
{
x - 2y = 5
x + y = 6
}
1 | syms x y |
Solving Equations Expressed in Symbols
- what if we are given a function expressed in symbols?
a*x^2 - b = 0
1 | syms x a b |
- x is always the first choice to be solved
- what if one wants to express b in terms of a and x?
1 | syms x a b |
Symbolic Differentiation微分: diff()
- Calculate the derivative of a symbolic function:
y = 4*x^5
1 | syms x |
Symbolic Integration积分: int()
1 | syms x; |
fsolve()
- A numeric root solver
- For example, solve this equation:
f(x) = 1.2x + 0.3 + x*sin(x)
1 | f2 = @(x) (1.2*x+0.3+x*sin(x)); |
其中fsolve的第二个参数是对方程成立的x的大概范围猜测,上面例子猜测为0
fzero()
- Another numeric root solver
- Find the zero if and only if the function crosses the x-axis
1 | f = @(x) x.^2; |
1 | f = @(x) x; |
fzero第二个参数也类似fsolve
Finding Roots of Polynomials: roots()
- find the roots of the polynomial
- roots only works for polynomial
1 | roots([1 -6 -12 81]) % f(x) = x^3-6*x^2-12*x+81 |
求解root 两种原理:
Bisection 二分法
Newton-Raphson Method(Open) 牛顿法
Assumption:
- f(x) continusous
- f`(x) known