CS计算机代考程序代写 scheme matlab ENGR20005

ENGR20005
Numerical Methods in Engineering
Workshop 6
Part A: MATLAB Livescripts
6.1 The livescript ENGR20005 Workshop6p1.mlx runs through Newton interpolation.
(a) Read through the livescript and make sure you understand what each line of code
does.
(b) Modify the livescript to approximate the Gaussian function
f(x) = e−x2 (6.1) within the interval −1 ≤ x ≤ 1. Use as many nodes as you deem fit.
6.2 The livescript ENGR20005 Workshop6p2.mlx runs through the use of Lagrange inter- polation to approximate functions.
(a) Read through the livescript and make sure you understand what each line of code does.
(b) Modify the livescript to approximate Eq. (6.1)
6.3 The livescript ENGR20005 Workshop6p3.mlx covers the use of linear and quadratic splines for interpolation.
(a) Read through the livescript and make sure you understand what each line of code does.
(b) Modify the livescript to approximate Eq. (6.1)
1

Part B: Problems
6.4 *The Witch of Agnesi is a function that appears prominently in probability theory, and after some scaling may be written as
f(x) = 1 1+25×2
(6.2)
which has been plotted below.
1
0.8
0.6
0.4
0.2
0
−1 −0.8−0.6−0.4−0.2 0 0.2 0.4 0.6 0.8 1
x
We’ll attempt to use Lagrange interpolation to approximate this function. (a) Evaluate Eq. (6.2) at the following points
i. xi ∈{−1,0,1}.
ii. xi ∈{−1,−0.75,−0.5,−0.25,0,0.25,0.5,0.75,1}
(b) Determine the Lagrange polynomial using the points you determined in part (a) and plot it along with Eq. (6.2). What do you notice?
This effect where the ends diverge rapidly as we increase number of Lagrange interpolation nodes is called Runge’s phenomena.
(c) Repeat parts (a) and (b) with the points
xi ∈{−1.0000,−0.8998,−0.6772,−0.3631,0.0000,0.3631,0.6772,0.8998,1.0000}
What happens now?
These are called Gauss–Lobatto–Legendre (GLL) nodes and are very nearly the optimal choice of interpolation points.
2
f (x)

(d) Repeat the exercise with quadratic Spline interpolation. Which method performs better?
6.5 Consider the function
(a) Show that the zeroth and first divided differences are given by
f[x0] = 1 1−x0
f[x0,x1] = 1 (1−x0)(1−x1)
f(x)= 1 1−x
(6.3)
(b) Show that the nth divided difference is given by f[x0,x1,…,xn] = 1
(1−x0)(1−x1)···(1−xn) (c) Hence show that the nth order Newton interpolant is given by
1 ≈ 1 + x − x0 + · · · + (x − x0) · · · (x − xn−1) 1−x 1−x0 (1−x0)(1−x1) (1−x0)···(1−xn)
(6.4) (d) Take the limit of Eq. (6.4) as xi → 0, i = 0,…,n. Compare your answer with
the Taylor series of Eq. (6.3) about the point x = 0.
6.6 [Challenge.] Suppose we interpolate a function f ∈ Cn+1, i.e. it has n + 1 continuous derivatives, using n + 1 nodes, xi ∈ {x0, x1, . . . , xn}, within the interval [a, b]. Then the error in the Lagrange polynomial pn for each t ∈ [a, b] is given by
E(t)=f(t)−pn(t)= (t−x0)(t−x1)···(t−xn)f(n+1)(ξ) (6.5) (n+1)!
for some ξ ∈ [a, b].
This might seem quite useless on its own, but whenever we need to know the error in approximating a function with a polynomial, such as determining the convergence of numerical integration schemes, it’s nice to have it.
(a) Show that Eq. (6.5) is trivially true at each nodal point.
(b) To prove the result for arbitrary t ̸= xi, we define the function
G(x) = E(x) − Ψ(x)E(t) Ψ(t)
with Ψ(x) = (x − x0) · · · (x − xn).
i. Show that G has at least n + 2 distinct roots within the interval [a, b].
(6.6)
3

ii. Use the mean value theorem to show that G′ has at least n + 1 distinct roots in [a, b].
iii. Argue that G(j)(x) has at least n + 2 − j distinct roots in [a, b].
iv. Show that the (n + 1)st derivative of G is
G(n+1)(x) = f(n+1)(x) − (n + 1)!E(t) (6.7) Ψ(t)
v. Apply your result in part iii. to show that there is at least one root of G(n+1) within [a, b], and denote it ξ. Using this and Eq. (6.7), obtain Eq. (6.5).
(c) Using your results from (a) and (b), conclude that Eq. (6.5) is true for all t ∈ [a, b]. (d) Consider the function
f(x) = log10(x) (6.8)
i. Suppose we interpolate f between the points x0 = 1 and x1 = 2 with a linear
Lagrange polynomial. Use Eq. (6.5) to give a bound on the error.
ii. Determine the linear Lagrange polynomial between x0 = 1 and x1 = 2. Use this to verify your prediction in part i.
4