【代码】Numerical_Analysis
基于 UIC 金融数学的课程 Numerical Analysis 中代码的复习笔记;
The Bisection Method
1 |
|
Fixed-point Iteration
1 |
|
Newton’s Method
1 |
|
nth Lagrange Interpolation Polynomials
如果我们已知 n+1 个点的值
存在一个多项式
通过所有点
Code of Degree one
1 |
|
Code of Degree two
1 |
|
注意:预测的点应该在已知点的范围之间
Neville’s Iterated Interpolation
如果一个多项式建立在 k 个确定的点上 $x_{m_1},x_{m_2},…,x_{m_k}$。那么,此多项式可以表示为 $P_{m_1,m_2,…,m_k}$,$Q_{i,j}=P_{i-j,i-j+1,…,i-1,i}$
1 |
|
1 |
|
Numerical Differentiation
- The (n+1) -point formula to approximate $f^{\prime}\left(x_{j}\right)$
- Forward-Difference and Backward-Difference Formula
where $ \xi(x)$ lies between $x_{0}$ and $x_{0}+h$ . When $h>0$ , it is the forward-difference formula; The backward-difference formula if $h<0$ .
- Three-Point Endpoint Formula
where $\xi_{0}$ lies between $x_{0}$ and $x_{0}+2 h$ .
- Three-Point Midpoint Formula
where $\xi_{1}$ lies between $x_{0}-h$ and $x_{0}+h$ .
- Five-Point Endpoint Formula
where $\xi_{0}$ lies between $x_{0}$ and $x_{0}+4 h$ .
- Five-Point Midpoint Formula
where $\xi_{1}$ lies between $x_{0}-2 h$ and $x_{0}+2 h$ .
- Second Derivative Midpoint Formula (To approximate $f^{\prime \prime}\left(x_{0}\right)$)
where $\xi$ lies between $x_{0}-h$ and $x_{0}+h$ .
Numerical Integration
The $(n+1)$ -point Closed Newton-Cotes Formulas:
Use $x_{i}=x_{0}+i h$ , for $i= 0,1, \cdots, n$ , where $x_{0}=a, x_{n}=b$ and $h=(b-a) / n$ . The endpoints of the closed interval [a, b] are included as nodes.
where $a_{i}=\int_{a}^{b} L_{i}(x) \mathrm{d} x$ .
- Trapezoidal Rule (n=1)
- Simpson’s Rule (n=2)
- Simpson’s Three-Eights Rule (n=3)
The $(n+1)$-point Open Newton-Cotes Formulas:
Use $x_{i}=x_{0}+i h$, for $i=$ $0,1, \cdots, n$, where $h=(b-a) /(n+2), x_{0}=a+h$ and $x_{n}=b-h$. Label the endpoints as $x_{-1}=a$ and $x_{n+1}=b$. Open formulas contain all the nodes within the open interval $(a, b)$.
where $a_{i}=\int_{a}^{b} L_{i}(x) \mathrm{d} x$.
- Midpoint Rule $(n=0)$
Composite Numerical Integration
- Composite Simpsons rule: Let $f \in C^{4}[a, b], n$ be even, $h=(b-a) / n$, and $x_{j}=a+j h$, for each $j=0,1, \cdots, n$. There exists a $\mu \in(a, b)$ for which the Composite Simpsons rule for $n$ subintervals can be written with its error term as
- Composite Trapezoidal rule: Let $f \in C^{2}[a, b], h=(b-a) / n$, and $x_{j}=a+j h$, for each $j=0,1, \cdots, n$. There exists a $\mu \in(a, b)$ for which the Composite Trapezoidal rule for $n$ subintervals can be written with its error term as
- Composite Midpoint rule: Let $f \in C^{2}[a, b], n$ be even, $h=(b-a) /(n+2)$, and $x_{j}=a+(j+1) h$, for each $j=-1,0, \cdots, n+1$. There exists a $\mu \in(a, b)$ for which the Composite Midpoint rule for $n+2$ subintervals can be written with its error term as
1 |
|
1 |
|
Initial Value Problems for ODEs
Approximate the solution $y(t)$ to an initial-value problem
Euler’s Method
- Forward Euler’s Method:
- Backward Euler’s Method:
Higher-Order Taylor Methods
- Taylor method of order $n$ :where
- Forward Euler’s Method is Taylor’s method of order one.
Runge-Kutta Method
Runge-Kutta methods of order two (RK2):
Midpoint method: with local truncation error $O\left(h^{2}\right)$
for each $i=0,1, \cdots, N-1$.
Modified Euler method: with local truncation error $O\left(h^{2}\right)$
for each $i=0,1, \cdots, N-1$.
Runge-Kutta methods of order four (RK4):
for each $i=0,1, \cdots, N-1$.