1
8.24 Write a MATLAB user-defined function that evaluates the second derivative of a function that is
given by a set of discrete data points with unequal spacing. For the function name use yd = SndDeriv-
Uneq(x,y). The input arguments x and y are vectors with the coordinates of the points, and the output
argument yd is a vector with the values of the second derivative at each point. Use the following scheme
for the differentiation. Write a third-order Lagrange polynomial for four points , , ,
and , and derive formulas for the second derivative of the polynomial at each of the four points.
SndDerivUneq uses the formula for for calculating the second derivative at the first data
point, and the formula for and for calculating the second derivative at the last data
point and one point before the last, respectively. The formula for is used in all the points in
between. Use the function to calculate the second derivative of the function that is given by the following
set of points:
Solution
A third-order Lagrange polynomial for four points , , , and is:
–1 –0.6 –0.3 00.5 0.8 1.6 2.5 2.8 3.2 3.5 4
–3.632 –0.8912 0.3808 1.0 0.6487 –0.3345 –5.287 –12.82 –14.92 –16.43 –15.88 –9.402
fx() xx
i
–()xx
i1+
–()xx
i2+
–()
xi1– xi
–()xi1– xi1+
–()xi1– xi2+
–()
—————–—————-————————————————-——– yi1–
xx
i1–
–()xx
i1+
–()xx
i2+
–()
xixi1–
–()xixi1+
–()xixi2+
–()
—————–———————————————————––yi
++=