ENGR20005
Numerical Methods in Engineering
Workshop 8
Part A: MATLAB Livescripts
8.1 The livescript ENGR20005 Workshop8p1.mlx runs through the use of MATLAB func- tions to differentiate functions.
(a) Read through the livescript and make sure you understand what each line of code does.
(b) Modify the livescript to take derivatives of the functions i. f(x)=cos(x2)
ii. φ(x,y)=exp(x2 +y2)
8.2 The livescript ENGR20005 Workshop8p2.mlx runs through numerical differentiation.
(a) Read through the livescript and make sure you understand what each line of code does.
(b) Modify the livescript to evaluate the derivative of
f(x) = cos(x2) (8.1)
between 0 ≤ x ≤ 1. Use as many points as you deem fit.
8.3 The livescript ENGR20005 Workshop8p3.mlx runs through spectral differentiation.
(a) Read through the livescript and make sure you understand what each line of code does.
(b) Modify the livescript to evaluate the derivative of Eq. (8.1) between −1 ≤ x ≤ 1. Use as many points as you deem fit.
1
Part B: Problems
8.4 (a) * For each of the following functions, use a 10 point central difference and spectral difference method to approximate the derivative for x ∈ [−1, 1].
i. f1(x) = |x3|
ii. f2(x) = exp (−x−2)
iii.f(x)= 1
3 1+x2
iv. f4(x) = x10
Compare your answers with the exact derivatives
i. f1′(x)=3x|x| ii. f′(x) = 2f2(x)
2 x3
iii. f3′ (x) = −2xf3(x)2
iv. f4′(x)=10×9
(b) * Repeat the previous problem with N = 1, . . . , 30 points and determine error in each case. Plot the error as a function of the number of points. Compare the convergence of each method.
8.5 Determine the truncation error of the following schemes (a) 4th order central difference
df = f(xi−2)−8f(xi−1)+8f(xi+1)−f(xi+2) dx i 12∆
(b) 4th order Pad ́e scheme
df +4df +df = 3[f(xi+1)−f(xi−1)]
dx i−1 (c) 6th order Pad ́e scheme
dx i
dx i+1 ∆
= f(xi+2)+28f(xi+1)−28f(xi−1)−f(xi−2) 12∆
df +3df +df dx i−1 dx i dx i+1
8.6 The central difference formula is defined as
df =f(xi+1)−f(xi−1)
dx i 2∆
(a) For exact derivatives, the product rule is given by
d(fg) =fdg +gdf dx dx dx
Does this hold with a central difference scheme? 2
(8.2)
(8.3)
(b) Show that
d(fg) =f ̄dg +g ̄df dxi idxi idxi
(8.4)
where the overbar denotes the average over the adjcent elements. f ̄=1[f(x )+f(x )]
8.7 Consider the function
i 2 i+1 i−1
f(ξ) = ξ7
(a) Use spectral differentiation to determine the derivative of Eq. (8.5) in the interval
ξ ∈ [−1, 1].
(b) Determine a mapping from the interval x ∈ [2, 10] to the standard interval ξ ∈
[−1, 1].
(c) Use your answer in part (b) and the chain rule to determine the derivative of
in the interval x ∈ [2, 10].
3
g(x) = x7
(8.5)