Numerical Methods Cheat Sheet: 1 Bisection Method
Numerical Methods Cheat Sheet: 1 Bisection Method
1 Bisection Method
Used to find the root of a function f (x) where f (x) = 0.
Steps
1. Choose an interval [a, b] where f (a) · f (b) < 0.
2. Compute the midpoint:
a+b
xn =
2
3. Evaluate f (xn ):
• If f (xn ) = 0, stop; xn is the root.
• If f (a) · f (xn ) < 0, set b = xn ; otherwise, set a = xn .
4. Repeat until |b − a| is sufficiently small.
Example
Solve cos(x) − x = 0 on the interval [0, 1] using the bisection method.
1. f (0) = cos(0) − 0 = 1, f (1) = cos(1) − 1 ≈ −0.4597. 2. Midpoint:
0+1
x1 = = 0.5
2
3. f (0.5) = cos(0.5) − 0.5 ≈ 0.3776.
2 Jacobi Method
Used to iteratively solve systems of linear equations AX = B.
Steps
1. Rewrite each equation in the form:
P (k)
(k+1) bi − j̸=i aij xj
xi =
aii
1
Example
Solve AX = B, where:
24 2.4 2 5
A= ,B = , X (0) =
−1.5 −15 5 2
After three iterations, the approximate solution for a is 0.1155.
Formula
For a set of points (x0 , y0 ), (x1 , y1 ), . . . , (xn , yn ), the divided differences are computed as:
f (xj ) − f (xi )
First-order: f [xi , xj ] =
xj − xi
f [xj , xk ] − f [xi , xj ]
Higher-order: f [xi , xj , xk ] =
xk − xi
Example
Given data:
x = [0.6, 1.1, 2.5, 3.1], y = [2.1, 5.3, 7.2, 10.0]
Evaluate f [0.6, 1.1, 2.5, 3.1]:
First-order differences: f [0.6, 1.1] = 6.4, f [1.1, 2.5] = 1.3571, f [2.5, 3.1] = 4.6667
Second-order differences: f [0.6, 1.1, 2.5] = −2.6541, f [1.1, 2.5, 3.1] = 1.6548
Third-order difference: f [0.6, 1.1, 2.5, 3.1] = 1.7236
Formula
The backward Newton polynomial is:
Pn (x) = f [xn ] + f [xn , xn−1 ](x − xn ) + f [xn , xn−1 , xn−2 ](x − xn )(x − xn−1 ) + . . .
Example
Given points:
x = [0.6, 1.1, 2.5, 3.1], y = [2.1, 5.3, 7.2, 10.0]
The backward Newton polynomial is:
P (x) = 10 + 4.6667(x − 3.1) + 1.6548(x − 3.1)(x − 2.5) − 2.6541(x − 3.1)(x − 2.5)(x − 1.1)
5 Lagrange Polynomial
Used to find a polynomial that passes through a given set of points using Lagrange basis
polynomials.
2
Formula
For points (x0 , y0 ), (x1 , y1 ), . . . , (xn , yn ), the Lagrange polynomial is:
n
X
P (x) = yi · ℓi (x)
i=0
Example
Given points:
x = [1, 2, 3], y = [2, 3, 6]
The Lagrange polynomial is:
(x − 2)(x − 3) (x − 1)(x − 3) (x − 1)(x − 2)
P (x) = 2 +3 +6
(1 − 2)(1 − 3) (2 − 1)(2 − 3) (3 − 1)(3 − 2)
6 Polynomial Interpolation
Polynomial interpolation is used to find a polynomial that passes through a given set of data
points.
Formula
The interpolating polynomial of degree n for points (x0 , y0 ), (x1 , y1 ), . . . , (xn , yn ) is given by:
n
X Y x − xj
P (x) = yi ·
i=0 0≤j≤n
xi − xj
j̸=i
Example
Given data points:
x = [0.6, 1.1, 2.5, 3.1], y = [2.1, 5.3, 7.2, 10.0]
Polynomial interpolation gives an approximate polynomial:
P (x) = 10 + 4.6667(x − 3.1) + 1.6548(x − 3.1)(x − 2.5) − 2.6541(x − 3.1)(x − 2.5)(x − 1.1)
7 Cholesky Decomposition
Used to decompose a symmetric positive definite matrix A into A = BB T , where B is a lower
triangular matrix.
Example
Given A is symmetric positive definite, and you are given:
X
a11 = 49 and of all entries in the first column of A = 46
To find the sum of all entries in the first column of B, use the Cholesky decomposition steps:
3
√
B11 = a11 = 7
The sum of the first column of A is given by:
n
X n
X
49 + ai1 = 46 =⇒ ai1 = −3
i=2 i=2
8 Newton’s Method
Given the equation x3 − sin(x) − 7 = 0 with the interval [1.3, 2.8], we apply Newton’s method
to find x3 and estimate ∆x3 .
Example
1. Choose an initial guess x0 = 2: 2. Compute f (x0 ) and f ′ (x0 ):
f (2) = 23 − sin(2) − 7 = 0.0907, f ′ (2) = 12.4161
0.0907
x1 = 2 − = 1.9927
12.4161
3. Compute x2 :
f (1.9927) = 0.047, f ′ (1.9927) = 11.935
0.047
x2 = 1.9927 − = 1.9888
11.935
4. Compute x3 :
f (1.9888) = 0.0155, f ′ (1.9888) = 11.9345
0.0155
x3 = 1.9888 − = 1.9875
11.9345
Estimate ∆x3
∆x3 = |x3 − x2 | = |1.9875 − 1.9888| = 0.0013