Docsity

Math 575A HW Set 7: Natural Cubic Splines, Derivatives, and Finite Differences, Assignments of Mathematical Methods for Numerical Analysis and Optimization

Toggle sidebar
bg1
Homework Set #7, Math 575A
Part I: This part is the analytical part.
1. Which of the properties of a natural cubic spline does the following
function posess and which properties does it not?
f(x) = ((x+ 1) + (x+ 1)3x∈[−1,0]
4 + (x−1) + (x−1)3x∈(0,1]
2. Let f(x) = √1 + cos x.
(a) Prove fis a periodic function with periodicity of 2π;
(b) Find the trigonometric polynomial that interpolates fat x0=
0, x1=π.
3. Derive the following two formulas for approximating the third deriva-
tive. Which one is more accurate?
(a) f000(x)≈1
h3(f(x+ 3h)−3f(x+ 2h) + 3f(x+h)−f(x));
(b) f000(x)≈1
2h3(f(x+ 2h)−2f(x+h) + 2f(x−h)−f(x−2h)).
4. Derive a numerical differentiation formula of order O(h4) by applying
Richardson extrapolation to
f0(x) = 1
2h[f(x+h)−f(x−h)] −h2
6f000(x)−h4
120f(5)(x)− · · ·
Part II: This part is practical
1. Write a code that uses
1
12h(−f(x+ 2h) + 8f(x+h)−8f(x−h) + f(x−2h))
to approximate f0(x), where f(x) = tan−1xand x=√2. (Note
f0(√2) = 1
3.). Output k, h, r, e. Here kis the iteration index, his
the step size, ris the approximate value of f0(x) and eis the error,
i.e. e=|1
3−r|. From a nicely displayed table of the error, estimate
the order of the finite difference approximation you just coded, by
repeatedly changing the value of h.
1
pf2

Partial preview of the text

Download Math 575A HW Set 7: Natural Cubic Splines, Derivatives, and Finite Differences and more Assignments Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

Homework Set #7, Math 575A

Part I: This part is the analytical part.

  1. Which of the properties of a natural cubic spline does the following function posess and which properties does it not?

f (x) =

{ (x + 1) + (x + 1)^3 x ∈ [− 1 , 0] 4 + (x − 1) + (x − 1)^3 x ∈ (0, 1]

  1. Let f (x) =

1 + cos x.

(a) Prove f is a periodic function with periodicity of 2π; (b) Find the trigonometric polynomial that interpolates f at x 0 = 0 , x 1 = π.

  1. Derive the following two formulas for approximating the third deriva- tive. Which one is more accurate?

(a) f ′′′(x) ≈ (^) h^13 (f (x + 3h) − 3 f (x + 2h) + 3f (x + h) − f (x)); (b) f ′′′(x) ≈ (^21) h 3 (f (x + 2h) − 2 f (x + h) + 2f (x − h) − f (x − 2 h)).

  1. Derive a numerical differentiation formula of order O(h^4 ) by applying Richardson extrapolation to

f ′(x) =

2 h [f (x + h) − f (x − h)] −

h^2 6 f ′′′(x) −

h^4 120 f (5)(x) − · · ·

Part II: This part is practical

  1. Write a code that uses 1 12 h

(−f (x + 2h) + 8f (x + h) − 8 f (x − h) + f (x − 2 h))

to approximate f ′(x), where f (x) = tan−^1 x and x =

  1. (Note f ′(
  1. = 13 .). Output k, h, r, e. Here k is the iteration index, h is the step size, r is the approximate value of f ′(x) and e is the error, i.e. e = | 13 − r|. From a nicely displayed table of the error, estimate the order of the finite difference approximation you just coded, by repeatedly changing the value of h.
  1. The following is a MATLAB code for the Richardson extrapolation algorithm on Page 510 of Kincaid&Chenney 1 for approximating the derivative of f (x) = ln x at x = 3. First copy the code to a M-file and try it in MATLAB. Make a copy of the code and then modify the new version to approximate the derivative of f (x) = sin(x^2 + 13 x) at x = 0. From a nicely displayed table of the error, estimate the order of the finite difference approximation you just coded, by repeatedly changing the value of h.

% hw7.m % Implemention of the Richardson extrapolation algorithm % on Page 510 of Kincaid&Cheney.

x = 3; h = 1; M = 6; D = zeros(M,M); % Set D to be an M by M matrix with % all zero entries for n = 1 : M % In MATLAB, index has to start from 1 hn = h/2^(n-1); % Adapt the index in subsequent places D(n,1) = ( log(x+hn) - log(x-hn) ) / (2*hn); end for k = 2 : M for n = k : M D(n,k) = D(n,k-1) + ( D(n,k-1) - D(n-1,k-1) ) / (4^(k-1) - 1 ); end end

format long; disp(D);

(^1) on some editions of the book this is on page 436