



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Numerical Computing F’04 A. Kapila
Assignment 5 Solutions
given with a spacing of h.
(a) If linear interpolation is used, how small must h be to ensure that the interpolation error does
not exceed 5 × 10 − 6 ?
(b) Repeat part (a) for quadratic interpolation.
(a) This is similar to a problem done in class for f (x) = sin x.
Let f (x) be defined in [0, h]. The error of linear interpolation of f (x) is given, in absolute value,
by
|f
′′ (ξ)||x(x − h)|,
where 0 < ξ < h. Let |f ′′ (ξ)| be bounded by M 2. Note that the maximum of |x(x − h)| is
h 2 / 4. Therefore,
M 2 h
2
Now, for f (x) = ln x, f
′′ (x) = − 1 /x
2 , whose global maximum, in absolute value, in the interval
[1, 7] is M 2 = 1. For the given tolerance to be satisfied, therefore, we must have
h 2
− 6 ,
or h <
− 3 = 6. 32 × 10
− 3
. Thus h = 0.006 will do.
(b) In a completely analogous way, for quadratic interpolation on [0, 2 h], the absolute value of the
error is given by
|f
′′′ (ξ)||x(x − h)(x − 2 h)|,
where now 0 < ξ < 2 h. Let |f
′′′ (ξ)| be bounded by M 3. Also, the maximum of |x(x−h)(x− 2 h)|
easily seen to be 2h
3 / 3
M 3 h
3
For f (x) = ln x, f
′′′ (x) = 2/x
3 , whose global maximum, in absolute value, in the interval [1, 7]
is M 3 = 2. For the given tolerance to be satisfied, therefore, we must have
2 h
3
− 6 ,
or h <
45
√ 3 2
− 2 = 3. 39 × 10
− 2
. Thus, h = 0.03 will suffice.
R (ohms) as a function of absolute temperature T (degrees Kelvin).
Theoretical considerations suggest that the relationship between the temperature and the resistance
can be approximated by a fit of the form
= a + b ln R + c(ln R)
3 .
(a) Observe that the fitting function is a polynomial of degree 3 of the independent variable is taken
to be ln R and the dependent variable 1/T. Write down the normal equations and the associated
matrix problem that must be solved to find the coefficients a, b and c. Do this by writing down
an expression for the error associated with the fit, and then minimizing the error.
(b) Solve the problem for the given data. The solution may be obtained by using Matlab’s backslash
( \ ) command for solving linear systems. (Do not use Matlab’s polyfit command.)
(c) Graph both the data points and the fitting function on a suitably labelled (R, T ) graph.
(d) Now find a fitting polynomial of the form T = A + BR + CR
2
3 that fits the same data
in the least-squares sense, and plot it on the same graph as above. (This can be done by using
Matlab’s polyfit and polyval commands.) Which fit do you prefer and why?
(a) The mean-squared error is given by
11 ∑
i=
a + b ln Ri + c(ln Ri)
3 −
Ti
The normal equations, obtained by minimizing the error with respect to the coefficients a, b, and
c are
∂a
11 ∑
i=
a + b ln Ri + c(ln Ri)
3
11 ∑
i=
Ti
∂a
11 ∑
i=
a + b ln Ri + c(ln Ri)
3
ln Ri =
11 ∑
i=
ln Ri
Ti
∂a
11 ∑
i=
a + b ln Ri + c(ln Ri)
3
(ln Ri)
11 ∑
i=
(ln Ri) 3
Ti
The corresponding linear system is
i= ln Ri
i= (ln Ri)
3
∑ 11
i= ln Ri
i= (ln Ri)
2
i= (ln Ri)
4
∑ 11
i= (ln Ri) 3
i= (ln Ri) 4
i= (ln Ri) 6
a
b
c
11 i=
1 Ti ∑ 11 i=
ln Ri Ti ∑ 11
i=
(ln Ri) 3
Ti
The six conditions identified above lead to
−a + b − c + d = 0 ,
a + b + c + d = 0 ,
3 a − 2 b + c = 0 ,
3 a + 2b + c = 0 ,
− 6 a + 2b = 0 ,
6 a + 2b = 2.
These equations are inconsistent. For example, the last two yield a = 1/ 6 , b = 1/ 2. The third and
fourth equations, when subtracted, give b = 0 which is a contradiction. Thus s(x) is NOT a cubic
spline.
∫ (^3) h
0 f (x) dx be approximated by the quadrature formula
Q = a 0 f (0) + a 1 f (h) + a 2 f (2h).
Determine the ai in order to maximize the precision of the formula.
We insist that the formula be exact for f (x) = 1, x, and x 2
. Then we get
a 0 + a 1 + a 2 =
3 h
0
1 dx = 3h,
ha 1 + 2ha 2 =
3 h
0
x dx = 9h
2 / 2 ,
h
2 a 1 + 4h
2 a 2 =
3 h
0
x
2 dx = 9h
3 .
The linear system leads to
a 0 = 3h/ 4 , a 1 = 0, a 2 = 9h/ 4.