0% found this document useful (0 votes)
18 views79 pages

Numerical Methods: Power & SVD Techniques

The document covers numerical methods, specifically the Power Method for finding dominant eigenvectors and eigenvalues, and Singular Value Decomposition (SVD) for solving ill-conditioned problems. It also discusses polynomial interpolation techniques, including monomial and Lagrange interpolation, highlighting their construction, evaluation complexities, and applications. Examples are provided to illustrate the methods, including calculations for eigenvalues and polynomial fitting.

Uploaded by

Ali Huseynov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views79 pages

Numerical Methods: Power & SVD Techniques

The document covers numerical methods, specifically the Power Method for finding dominant eigenvectors and eigenvalues, and Singular Value Decomposition (SVD) for solving ill-conditioned problems. It also discusses polynomial interpolation techniques, including monomial and Lagrange interpolation, highlighting their construction, evaluation complexities, and applications. Examples are provided to illustrate the methods, including calculations for eigenvalues and polynomial fitting.

Uploaded by

Ali Huseynov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

BLG 202E

Numerical Methods
Recitation 2
Tuesday, June 8, 2021
Res. Assist. Meral Kuyucu
CHP 8

Meral Kuyucu, 2021 BLG 202E Numerical Methods 91


Power Method
Use the Power Method to find the dominant eigenvector and the corresponding eigenvalue.

Meral Kuyucu, 2021 BLG 202E Numerical Methods 92


Rayleigh Quotient

To determine the eigenvalue for an eigenvector, use the Rayleigh quotient:

Meral Kuyucu, 2021 BLG 202E Numerical Methods 93


Power Method Example
• Complete 6 iterations of the Power Method to approximate the
dominant eigenvector of the matrix given below. Use initial
approximation x0.

2 -12 1
•A= x=
1 -5 1

Meral Kuyucu, 2021 BLG 202E Numerical Methods 94


Power Method Solution

(Approaching [3, 1])

Meral Kuyucu, 2021 BLG 202E Numerical Methods 95


Power Method Solu9on

Which is a good estimate of the dominant eigenvalue (𝜆"= −2)

Meral Kuyucu, 2021 BLG 202E Numerical Methods 96


Singular Value Decomposition
• Sometimes, a solution to the problem Ax = b is impossible to find
because it is an ill conditioned number (i.e. condition number is very
large).
• Thus, it is favorable to attempt to regularize it.
• This means, replace the given problem intelligently by a nearby
problem which is better conditioned.
• Using SVD this can be done by setting the singular values below a
cutoff tolerance to 0, and minimizing the l2-norm of the solution to
the resulting underdetermined problem.
[Link]
Meral Kuyucu, 2021 BLG 202E Numerical Methods 97
Singular Value Decomposition
• A = PDP-1
• P = Eigenvectors
• D = Diagonal Matrix of Eigenvalues
• Great, but not every matrix is diagonalizable.
• SVD: 𝐴 = 𝑈Σ𝑉 S
• U: Orthogonal Left Singular Vectors
• Σ: Diagonal Matrix of Singular Values
• 𝑉 O :Orthogonal Right Singular Vectors
• Advantage: you can do it to any matrix

Meral Kuyucu, 2021 BLG 202E Numerical Methods 98


Singular Value Decomposi9on
• Suppose 𝐴 = 𝑈Σ𝑉 O
• 𝐴𝐴O = 𝑈Σ𝑉 O 𝑈Σ𝑉 O O

• 𝐴𝐴O = 𝑈Σ𝑉 O 𝑉Σ O 𝑈 O
• 𝐴𝐴O = 𝑈Σ !𝑈 O

• Σ != Eigenvalues of 𝐴𝐴O
• 𝑈 & 𝑈 O = Eigenvectors of 𝐴𝐴O

• The same can be done for 𝐴O 𝐴


• Σ . = Eigenvalues of𝐴> 𝐴
• V & 𝑉 > = Eigenvectors of 𝐴> 𝐴

Meral Kuyucu, 2021 BLG 202E Numerical Methods 99


Best Lower Rank Approximation

Meral Kuyucu, 2021 BLG 202E Numerical Methods 100


SVD Example
• Find the SVD of 2 2

1 1

Meral Kuyucu, 2021 BLG 202E Numerical Methods 101


SVD Solution
Step 1: Calculate 𝐴𝐴O and find Eigenvalues and Eigenvectors
Eigenvectors:
Eigenvalues:
2 2 2 1 8 4 𝑣B 𝑣?
𝜆B = 10
= 𝜆? = 0 2 -1
1 1 2 1 4 2
1 2

Step 2: Calculate 𝐴O 𝐴and find Eigenvalues and Eigenvectors


Eigenvectors:
2 2 Eigenvalues:
2 1 1 1 𝑣B 𝑣?
𝜆B = 10
=(5) 𝜆? = 0 1 1
2 1 1 1 1 1
1 -1
Meral Kuyucu, 2021 BLG 202E Numerical Methods 102
SVD Solution
# 2 -1
•𝑈=
J
1 2

10 0
•Σ
0 0

1 1
S #
•𝑉 =
% 1 -1
[Link]

Meral Kuyucu, 2021 BLG 202E Numerical Methods 103


CHP 10 – Polynomial Interpolation

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 3


Interpolation

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 4


Interpolation
• In general, it is important to distinguish two stages in the
interpolation process:
• Constructing
• Evaluating
• Why polynomial interpolation?
• easy to construct and evaluate
• easy to sum and multiply
• easy to differentiate and integrate
• have widely varying characteristics despite their simplicity

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 5


Monomial Interpolation

Vandermonde Matrix Calculated Data


Coefficients Values
6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 6
Monomial Interpolation

• We wish to create a linear combination


of our basis functions that best
represents the original function.

• Choose basis functions as powers of x.

• Find coefficients c to form the linear


combination.

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 7


Monomial Interpolation
• Coefficients (cj) are not indicative of the interpolated function
• Problematic if data points are unevenly spaced
• The Vandermonde matrix (X) is often ill-conditioned
• Nonsingular, unique interpolating polynomial
• The complexity is:
• Constructed with Gaussian Elimination: O((2/3)n3)
• Evaluation in Horner Form: O(2n)

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 8


Monomial Interpolation Problem
• Find an interpolating polynomial with the monomial interpolation
method.

x 0 1 -1 2 -2
f(x) -5 -3 -15 39 -9

n+1 = 5 (Number of data points)


n = 4 (Max degree of polynomial)

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 9


Monomial Interpolation Solution
• Form the Vandermonde Matrix: x 0 1 -1 2 -2
f(x) -5 -3 -15 39 -9

Basis Functions
∅! (𝑥) = 1 ∅" (𝑥) = 𝑥 ∅# (𝑥) = 𝑥 # ∅$ (𝑥) = 𝑥 $ ∅% (𝑥) = 𝑥 %
𝑥=0 1 0 0 0 0
Points 𝑥=1 1 1 1 1 1
of
Evaluation 𝑥 = −1 1 -1 1 -1 1
𝑥=2 1 2 4 8 16
𝑥 = −2 1 -2 4 -8 16

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 10


Monomial Interpolation Solution
• Solve the linear system:
1 0 0 0 0 c0 -5 c0 -5

1 1 1 1 1 c1 -3 c1 4

1 -1 1 -1 1 * c2 = -15 c2 = -7

1 2 4 8 16 c3 39 c3 2

1 -2 4 -8 16 c4 -9 c4 3

The polynomial is: 𝑣 𝑥 = 𝑝* 𝑥 = −5 + 4𝑥 − 7𝑥 + + 2𝑥 , + 3𝑥 *

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 11


Monomial Interpolation Solution

x 0 1 -1 2 -2
f(x) -5 -3 -15 39 -9

𝑣 𝑥 = 𝑝* 𝑥 = −5 + 4𝑥 − 7𝑥 + + 2𝑥 , + 3𝑥 *
6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 12
Lagrange Interpolation

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 13


Lagrange Interpolation
• Not as simple as monomial basis.
• The complexity is:
• Construction: O(n2)
• Evaluation: O(n)
• Coefficients (cj) indicative of data
• Useful for function manipulation such as integration and differentiation
• Stable
• Even if degree is large or abscissae spread apart

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 14


Lagrange Interpolation Problem
• Calculate f(4) using Lagrange polynomials of order 1 to 3 for the data
given below:

x 1 2 3 5 7 8
f(x) 3 6 19 99 291 444

f(4) = ?

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 15


Lagrange Interpolation Solution
• FO using points x0 = (3, 19) and x1 = (5, 99) à (n = 1)
./.! ./0
• 𝐿- 𝑥 = ." /.!
= ,/0
./." ./,
• 𝐿1 𝑥 = =
.! /." 0/,

15(./0) 55(./,)
• 𝑣 𝑥 = ∑423- 𝐿2 𝑥 𝑓 𝑥2 = 𝐿- 𝑥 𝑓 𝑥- + 𝐿1 𝑥 𝑓 𝑥1 = ,/0
+ 0/,

15(*/0) 55(*/,)
•𝑣 4 = ,/0
+ 0/,
= 9.5 + 49.5 = 59

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 16


Lagrange Interpolation Solution
• SO using points x0 = (2, 6), x1 = (3, 19) & x2 = (5, 99) à (n = 2)
"#"! "#"# "#$ "#&
• 𝐿! 𝑥 = "" #"! "" #"#
= %#$ %#&
"#"" "#"# "#% "#&
• 𝐿' 𝑥 = "! #"" "! #"#
= $#% $#&
"#"" "#"! "#% "#$
• 𝐿% 𝑥 = =
"# #"" "# #"! &#% &#$
• 𝑣 𝑥 = ∑423- 𝐿2 𝑥 𝑓 𝑥2 = 𝐿- 𝑥 𝑓 𝑥- + 𝐿1 𝑥 𝑓 𝑥1 + 𝐿+ 𝑥 𝑓 𝑥+ =
./, ./0 ./+ ./0 ./+ ./,
• 𝑣 𝑥 = 6 ∗ +/, +/0 + 19 ∗ ,/+ ,/0 + 99 ∗ 0/+ 0/,
*/, */0 */+ */0 */+ */,
•𝑣 4 = 6 ∗ +/, +/0 + 19 ∗ ,/+ ,/0 + 99 ∗ 0/+ 0/, = −2 + 19 + 33 = 50

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 17


Lagrange Interpolation Solution
• TO using points x0 = (2, 6), x1 = (3, 19), x2 = (5, 99) & x3 = (7, 291) à (n = 3)
./.! ./.# ./.$ ./, ./0 ./6
• 𝐿- 𝑥 = ." /.! ." /.# ." /.$
= +/, +/0 +/6
./." ./.# ./.$ ./+ ./0 ./6
• 𝐿1 𝑥 = =
.! /." .! /.# .! /.$ ,/+ ,/0 ,/6
./." ./.! ./.$ ./+ ./, ./6
• 𝐿+ 𝑥 = =
.# /." .# /.! .# /.$ 0/+ 0/, 0/6
./." ./.! ./.# ./+ ./, ./0
• 𝐿, 𝑥 = .$ /." .$ /.! .$ /.#
= 6/+ 6/, 6/0
• 𝑣 𝑥 = ∑$!"# 𝐿! 𝑥 𝑓 𝑥! = 𝐿# 𝑥 𝑓 𝑥# + 𝐿% 𝑥 𝑓 𝑥% + 𝐿& 𝑥 𝑓 𝑥& + 𝐿' 𝑥 𝑓 𝑥' =
()' ()* ()+ ()& ()* ()+ ()& ()' ()+ ()& ()' ()*
• 𝑣 𝑥 =6∗ + 19 ∗ + 99 ∗ + 291 ∗
&)' &)* &)+ ')& ')* ')+ *)& *)' *)+ +)& +)' +)*
,)' ,)* ,)+ ,)& ,)* ,)+ ,)& ,)' ,)+ ,)& ,)' ,)*
• 𝑣 4 = 6∗ + 19 ∗ + 99 ∗ + 291 ∗ = 48
&)' &)* &)+ ')& ')* ')+ *)& *)' *)+ +)& +)' +)*

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 18


Lagrange Interpolation Solution
• FO – f(4) = 59
• SO – f(4) = 50
• TO – f(4) = 48

• As long as we use higher orders, we get better and more accurate


results.
• Third order is better than second, and second is better than first and
so on…
• As we increase the number of terms in our calculations, the error
decreases.
6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 19
Newton’s Basis Interpolation
• Wish to add new data points
without changing the entire
interpolant.
• We require:
• New basis function cannot
disturb prior interpolation:
• φj (xi) = 0 for i < j.
• Old basis function does not
need information about new
data values: φj(x) is
independent of (xi, yi) for i > j.
6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 20
Newton’s Basis Interpolation Problem
• Calculate f(4) using Newton’s Basis of order 3 for the data given
below:

x 1 2 3 5 7 8
f(x) 3 6 19 99 291 444

f(4) = ?

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 21


Newton’s Basis Interpolation Solution
x 1 2 3 5 7 8
f(x) 3 6 19 99 291 444

• 𝑥! = 2 , 𝑥' = 3, 𝑥% = 5& 𝑥$ = 7
• ∅! 𝑥 = 1
∅! (𝑥) ∅" 𝑥 ∅# 𝑥 ∅$ 𝑥
• ∅' 𝑥 = (𝑥 − 2)
𝒙! 1 0 0 0
• ∅% 𝑥 = (𝑥 − 2)(𝑥 − 3)
𝒙" 1 1 0 0
• ∅$ 𝑥 = (𝑥 − 2)(𝑥 − 3)(𝑥 − 5)
𝒙# 1 3 6 0

𝒙$ 1 5 20 40

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 22


Newton’s Basis Interpolation Solution
x 1 2 3 5 7 8
f(x) 3 6 19 99 291 444

• 𝑥! = 2 , 𝑥' = 3, 𝑥% = 5& 𝑥$ = 7
1 0 0 0 c0 6 c0 6

1 1 0 0 c1 19 c1 13
* = =
1 3 6 0 c2 99 c2 9

1 5 20 40 c3 291 c3 1

𝑣 𝑥 = 𝑝' 𝑥 = 6 + 13 𝑥 − 2 + 9 𝑥 − 2 𝑥 − 3 + 𝑥 − 2 𝑥 − 3 𝑥 − 5
𝑣 4 = 6 + 13 4 − 2 + 9 4 − 2 4 − 3 + 4 − 2 4 − 3 4 − 5 = 48

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 23


Newton’s Divided Difference

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 24


Newton’s Divided Difference Problem
• Construct the Newton Divided Difference Table and find the Newton
Interpolation Polynomial for the following dataset:
𝑖 𝒙𝒊 𝒚𝒊 = 𝒇(𝒙𝒊 )
0 0 0
1 1 1
2 2 8
3 3 27
4 4 64

By observation, our function is actually 𝑓(𝑥) = 𝑥 ,

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 25


Newton’s Divided Difference Problem
𝑖 𝒙𝒊 𝒇[𝒙𝒊 ] 𝒇[𝒙𝒊'𝟏 , 𝒙𝒊 ] … … …

0 0 0
1−0
=1
1−0 7−1
1 1 1 =3
2−0 6−3
8−1 =1
=7 3−0 1−1
2−1 19 − 7 =0
2 2 8 =6 4−0
3−1
9−6
27 − 8 =1
= 19 4−1
3−2 37 − 19
3 3 27 =9
4−2
64 − 27
= 37
4−3
4 4 64

𝑣 𝑥 = 0 + 1 𝑥−0 + 3 𝑥−0 𝑥−1 + 1 𝑥−0 𝑥−1 𝑥−2 + 0 𝑥−0 𝑥−1 𝑥−2 𝑥−3
𝑣 5 = 0 + 1 5−0 + 3 5−0 5−1 + 1 5−0 5−1 5−2 + 0 5−0 5−1 5−2 5−3
𝑣 5 = 0 + 5 + 3 ∗ 5 ∗ 4 + 1 ∗ 5 ∗ 4 ∗ 3 + 0 = 125
6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 26
Basis Comparison

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 27


Error Analysis

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 28


Divided Difference and Derivative

𝑓 DE1
(𝜉)
𝑓 𝑧-, 𝑧1, … , 𝑧D , 𝑧 =
𝑘+1 !

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 29


Error Analysis

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 30


Error Analysis Problem
!
• 𝑓 𝑥 = "
on 2, 4 & 𝑥# = 2, 𝑥! = 2.75, 𝑥$ = 4 (n = 2)
"! %&" ()
• 𝑝(𝑥) = $$
− ''
+ ((
! ! Our error is bounded by:
• 𝑓 3 = 0.33333 & 𝑝 3 = 0.32955
% % 1 9 9
• 𝑒 3
!
=𝑓 3 −𝑝 3
!
= 0.003783
! 𝑒 𝑥 ≤ − ∗ − = ≈ 0.0351
% % % 16 16 256
+! $ +,
• 𝑓 * (𝑥) = "!
, 𝑓 ** (𝑥) = ""
, 𝑓′′′ 𝑥 = "#
-$$$ % +,/ &#
• 𝑒 𝑥 = 𝑥 − 𝑥# 𝑥 − 𝑥! 𝑥 − 𝑥$ = (𝑥 − 2)(𝑥 − 2.75)(𝑥 − 4)
%! %!
• Then we can bound e(x):
|+,/ &#|
• |𝑒 𝑥 | = max %! max |(𝑥 − 2)(𝑥 − 2.75)(𝑥 − 4)|
01/12 01"12
• max 𝜉 = 2
4 $&
• 𝑙𝑜𝑐𝑎𝑙 max 𝑥 = 𝑦=
% !#'
4 )
• 𝑙𝑜𝑐𝑎𝑙 min 𝑥 = (𝑦 = − ) (We choose this one due to absolute value. )
$ !,
6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 31
• Distinguish between the terms data fitting, interpolation, and
polynomial interpolation.

• In interpolation we construct a curve through the data points. In


doing so, we make the implicit assumption that the data points are
accurate and distinct.
• Curve fitting is applied to data that contain scatter (noise), usually due
to measurement errors. Here we want to find a smooth curve that
approximates the data in some sense. Thus the curve does not
necessarily hit the data points.
• In polynomial interpolation, the interpolant is a polynomial (the basis
functions are polynomials as opposed to trigonometric functions for
example).
6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 32
• What are basis functions?

• In mathematics, a basis function is an element of a particular basis for


a function space.
• Every function in the function space can be represented as a linear
combination of basis functions, just as every vector in a vector space
can be represented as a linear combination of basis vectors.

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 33


CHP 14 – Numerical Differentiation

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 34


Numerical Differentiation
• Given a function f(x) that is differentiable in the vicinity of a point x0,
it is often necessary to estimate the derivative fʹ(x) and higher
derivatives using nearby values of f.

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 35


Deriving Formulas Using Taylor Series

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 36


Forward Difference

[Link]
6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 37
Three Point Central Differentiation

[Link]
6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 38
Five Point Central Differentiation

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 39


Differentiation Problem
• Compute forward difference approximation of O(h), central difference
approximations of O(h2) and O(h4) for the first derivative of y = cos(x)
at x = pi/4 using a value of h = pi/12. Estimate the true percent
relative error for each approximation.

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 40


Analytical Solution & Function Values
BC
• = − sin 𝑥
BD
BC E
• ' = − sin = −0.707106
BD ) F
*
E IE E
• 𝑦 𝑥GHI = 𝑦 − = cos = 0.9659258
F JI JI
E E E
• 𝑦 𝑥GHJ = 𝑦 − = cos = 0.8660254
F JI K
E E
• 𝑦 𝑥G = 𝑦 = cos = 0.7071067
F F
E E E
• 𝑦 𝑥GLJ = 𝑦 + = cos = 0.5
F JI M
E IE NE
• 𝑦 𝑥GLI = 𝑦 + = cos = 0.258819
F JI JI

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 41


Forward Difference Differentiation True Value: -0.7071068

x f(x)
, #, ,
𝑥+'# = − = 0.9659258
% "# "#
, , ,
𝑥+'" = − = 0.8660254
% "# -
,
𝑥+ = 0.7071067
%
, , ,
𝑥+." = + = 0.5
% "# $
, #, /,
𝑥+.# = + = 0.258819
% "# "#

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 42


Three Point Differentiation True Value: -0.7071068

x f(x)
, #, ,
𝑥+'# = − = 0.9659258
% "# "#
, , ,
𝑥+'" = − = 0.8660254
% "# -
,
𝑥+ = 0.7071067
%
, , ,
𝑥+." = + = 0.5
% "# $
, #, /,
𝑥+.# = + = 0.258819
% "# "#

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 43


Five Point Differentiation True Value: -0.7071068

x f(x)
, #, ,
𝑥+'# = − = 0.9659258
% "# "#
, , ,
𝑥+'" = − = 0.8660254
% "# -
,
𝑥+ = 0.7071067
%
, , ,
𝑥+." = + = 0.5
% "# $
, #, /,
𝑥+.# = + = 0.258819
% "# "#

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 44


Error Analysis True Value: -0.7071068

x f(x)
, #, ,
𝑥+'# = − = 0.9659258
% "# "#
, , ,
𝑥+'" = − = 0.8660254
% "# -
,
𝑥+ = 0.7071067
%
, , ,
𝑥+." = % + "# = $
0.5
, #, /,
𝑥+.# = % + "# = 0.258819
"#

Method Value Error


Forward Difference (O(h)) -0.79108963 11.87696857 %
Three Point Central Difference (O(h2)) -0.69905703 1.13840705 %
Five Point Central Difference (O(h4)) -0.70699696 0.01531316 %

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 45


Unequally Spaced Data
• Use (n+1) points to fit an nth order polynomial and derivate that
polynomial.
• 𝑃𝑛(𝑥) = 𝑦0𝐿0(𝑥) + 𝑦1𝐿1(𝑥) + … + 𝑦𝑛𝐿𝑛(𝑥)
• The y values are constants. We only need to derivate the Li(x) functions.
• 𝑃’𝑛(𝑥) = 𝑦0𝐿0’(𝑥) + 𝑦1𝐿1’(𝑥) + … + 𝑦𝑛𝐿𝑛’(𝑥)
(x−x0)(x−x1)…(x−x(j−1))(x−x(j+1))…(x−xn) !
• 𝐿𝑗 𝑥 =
(xj−x0)(xj−x1)…(xj−x(j−1))(xj−x(j+1))…(xj−xn) = "
! )
• 𝐿′𝑗 𝑥 = " ∑(#$% *+*#
#&'
• Then, we can calculate the derivative at values of x.

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 46


x 10 12 13.75

Unequally Spaced Data f(x) 3.75 1.25 0

• 𝑥0 = 10, 𝑥1 = 12, 𝑥2 = 13.75, 𝑓′(11)


*+*O *+*Q *+), *+)-./0
• 𝐿% 𝑥 = * +* * +* = )%+), )%+)-./0
P O P Q
*+*P *+*Q *+)% *+)-./0
• 𝐿) 𝑥 = =
*O+*P *O+*Q ),+)% ),+)-./0 Naïve Linear Estimate:
*+*P *+*O *+)% *+),
• 𝐿, 𝑥 = * +* * +* = )-./0+)% )-./0+), 𝑦" − 𝑦!
=
12 − 10
= −0.8
Q P Q O 𝑥" − 𝑥! 1.25 − 3.75
*+), *+)-./0 *+)% *+)-./0
• 𝑃 𝑥 = 3.75 )%+), )%+)-./0 + 1.25 ),+)% ),+)-./0
,*+,0./0 ,*+,-./0
• 𝑃′ 𝑥 = 3.75 /.0 + 1.25 +-.0
,∗))+,0./0 ,∗))+,-./0
• f 1 11 ≈ 𝑃′ 11 = 3.75 + 1.25 = −1.25
/.0 +-.0

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 47


Roundoff and Data Error

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 48


• How does numerical differentiation differ from symbolic
differentiation?

• Symbolic differentiation finds the derivative of a formula with respect


to a variable produces a formula as an output. In general, symbolic
mathematics programs manipulate formulas to produce new
formulas, rather than performing numeric calculations based on
formulas.
• In numerical analysis, numerical differentiation describes algorithms
for estimating the derivative of a mathematical function or function
subroutine using values of the function and perhaps other knowledge
about the function.

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 49


• Define order of accuracy.

• In numerical analysis, order of accuracy quantifies the rate of


convergence of a numerical approximation of a differential equation
to the exact solution.

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 50


• What advantage does the formula derivation using Lagrange
polynomial interpolation have over using Taylor expansions?

• We are able to derive functions which have unequally spaced data


using the Lagrange polynomial.

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 51


CHP 15 – Numerical Integration

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 52


Basic Integration Rules

Exact Simpson

Trapezoidal Midpoint

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 53


Basic Quadrature Rules

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 54


Composite Quadrature Rules

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 55


Composite Quadrature Errors

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 56


Trapezoidal Integration (Single)
True Value: 1.640533
!.<
• ∫! 0.2 + 25𝑥 − 200𝑥 % + 675𝑥 $ − 900𝑥 = + 400𝑥 & 𝑑𝑥
• 𝑓 0 = 0.2 & 𝑓 0.8 = 0.232
!.%B!.%$%
• 𝐼>?@A = 0.8 − 0 = 0.1728
%
• 𝐸𝑟𝑟𝑜𝑟 = 1.640533 − 0.1728 = 1.467722
• 𝐸𝑟𝑟𝑜𝑟 = 89.5%

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 57


Trapezoidal Integration (Composite)

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 58


Trapezoidal Integration (Composite)
!.<
• ∫! 0.2 + 25𝑥 − 200𝑥 % + 675𝑥 $ − 900𝑥 = + 400𝑥 & 𝑑𝑥
• n = 2 & h = 0.4
• 𝑓 0 = 0.2 & 𝑓 0.4 = 2.456 & 𝑓 0.8 = 0.232
!.% B %∗%.=&C B !.%$%
• 𝐼>?@A = 0.8 − 0 = 1.0688
%∗%
• 𝐸𝑟𝑟𝑜𝑟 = 1.640533 − 1.0688 = 0.57173
• 𝐸𝑟𝑟𝑜𝑟 = 34.9%

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 59


Trapezoidal Integration

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 60


Midpoint Integration (Single)
True Value: 1.640533
!.<
• ∫! 0.2 + 25𝑥 − 200𝑥 % + 675𝑥 $ − 900𝑥 = + 400𝑥 & 𝑑𝑥
• 𝑓 0 = 0.2 & 𝑓 0.4 = 2.456 & 𝑓 0.8 = 0.232
!.<B!
• 𝐼DEF = 0.8 − 0 𝑓 = 0.8𝑓 0.4 = 0.8 ∗ 2.456 = 1.9648
%
• 𝐸𝑟𝑟𝑜𝑟 = 1.640533 − 1.9648 = 0.324267
• 𝐸𝑟𝑟𝑜𝑟 = 19.8%

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 61


Simpson Method

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 62


Simpson Integration (Single)
True Value: 1.640533
!.<
• ∫! 0.2 + 25𝑥 − 200𝑥 % + 675𝑥 $ − 900𝑥 = + 400𝑥 & 𝑑𝑥
• 𝑓 0 = 0.2 & 𝑓 0.4 = 2.456 & 𝑓 0.8 = 0.232
!.%B= %.=&C B!.%$%
• 𝐼GED = 0.8 − 0 = 1.367467
C
• 𝐸𝑟𝑟𝑜𝑟 = 1.640533 − 1.367467 = 0.2730667
• 𝐸𝑟𝑟𝑜𝑟 = 16.6%

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 63


Simpson Integration (Composite)
!.<
• ∫! 0.2 + 25𝑥 − 200𝑥 % + 675𝑥 $ − 900𝑥 = + 400𝑥 & 𝑑𝑥
• 𝑛 = 4 (ℎ = 0.2)
• 𝑓 0 = 0.2 & 𝑓 0.2 = 1.288 & 𝑓 0.4 = 2.456 & 𝑓 0.6 = 3.464 & 𝑓 0.8 = 0.232
!.%B= '.%<<B$.=C= B% %.=&C B!.%$%
• 𝐼GED = 0.8 − 0 = 1.623467
'%
• 𝐸𝑟𝑟𝑜𝑟 = 1.640533 − 1.623467 = 0.017067
• 𝐸𝑟𝑟𝑜𝑟 = 1.04 %

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 64


• Define quadrature rule.

• The basic idea of a quadrature rule is to replace the definite integral


by a sum of the integrand evaluated at certain points (called
quadrature points ) multiplied by a number (called quadrature
weights ).

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 65


• In what basic way is numerical integration easier than numerical
differentiation?
• Generally speaking, for humans (at least those humans who have taken a
calculus course) it is easier to differentiate a given function than to
integrate it: the recipes for differentiation are more automatic and require
less ingenuity.
• For computers employing floating point arithmetic, however, there are
certain aspects of inte- gration which make it in some sense easier to deal
with than differentiation. Indeed, differentiation may be considered as a
roughing operation whereas integration (finding the primitive function) is a
smoothing operation.
• Differentiation is easier than integration analytically. It can be performed
systematically on many very messy functions. However, differentiation
makes a curve more jagged or the derivative might not exist, even when
the function is continuous. Computing a derivative numerically is more
unstable than integration.
6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 66
• Define a composite quadrature method.

6/8/21 BLG 202E – Numercial Methods – Recitation 2 Meral Kuyucu 67

You might also like