Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Construct a free cubic spline to approximate f(x) = e^-x by using the values giv

ID: 3142019 • Letter: C

Question

Construct a free cubic spline to approximate f(x) = e^-x by using the values given by f(x) at x = 0, 0.25, 0.75, and x = 1.0. (You may use Matlab to solve the linear system). Integrate the spline over [0,1], and compare the result to integral_0^1 e^-x dx = 1-1/e. Use the derivatives of the spline to approximate f (0.5) and f(0.5). Compare the approximations to the actual values Compute the polynomial interpolant of degree three that passes through the above four data points. Plot the two interpolants you found on the same graph (using the Matlab commands plot) Plot the errors in the two interpolants on the same graph (using the Matlab commands plot). What are your observations?

Explanation / Answer

1) the free cubic spline, S(x) = a0 + a1x + a2x2 +a3x3

Given that f(x) = e-x

at x = 0 , f(0) = 1

x=0.25, f(0.25) = e-0.25

x = 0.75, f(0.25) = e-0.75

x =1 , f(1) = e-1

Substituting all values in the cubic spline,we get;

S(0) = 1 = a0

S(0.25) = e-0.25 = a0 + a1(0.25) + a2(0.25)2 +a3(0.25)3

S(0.75) = e-0.75 = a0 + a1(0.75) + a2(0.75)2 +a3(0.75)3

S(1) = e-1 = a0 + a1 + a2 +a3

Substituting a0 =1 in the equations, we get;

a1(0.25) + a2(0.25)2 +a3(0.25)3 = e-0.25 -1 ......(1)

a1(0.75) + a2(0.75)2 +a3(0.75)3 = e-0.75 -1 ......(2)

a1 + a2 +a3 = e-1 -1 ......(3)

Solving the above three equations we get,

a1 = -0.794748

a2= 0.0012862

a3 = -0.1639137

hence, S(x) = 1-(0.794748)x + (0.0012862)x2 - (0.1639137)x3

S'(x) = -(0.794748) + (0.0025724)x - (0.491741)x2

S''(x) = (0.0025724) - (0.983482)x

S(x)dx from x=0 to x=1

[1-(0.794748)x + (0.0012862)x2 - (0.1639137)x3]dx from x=0 to x=1 = 0.5620764

and

f(x)dx from x=0 to x=1

(e-x)dx from x=0 to x=1 = 1-e-1 = 0.63212

S'(x) = -(0.794748) + (0.0025724)x - (0.491741)x2

S'(0.5) = -(0.794748) + (0.0025724)*0.5 - (0.491741)*0.52 = -0.616397

f'(x) = -e-x

f'(0.5) = -e-0.5=-0.60653