 # Numerical Analysis Using Matlab

## Transcribed Text

1. Consider f(x) = xe−6x and the interpolating points {xi} 5 i=0 = {0, 0.2, 0.4, 0.6, 0.8, 1}. You may use the built-in MATLAB function spline or myspline on the course webpage in the following calculations. (a) Complete the MATLAB code myspline.m on the course webpage by adding the endpoint conditions for clamped splines. Attach your code to the report. (b) Compute the natural cubic spline S(x) that interpolates f(x) at the given points. Find S0(x) and S4(x), and verify that they satisfy the natural boundary conditions. You need to use myslpine for this problem since the built-in spline does not have the option of natural spline. (c) Compute the clamped cubic spline s(x) that interpolates f(x) at the given points. Find s0(x) and s4(x), and verify the boundary conditions at x0 and x5. (d) Compute the not-a-knot cubic spline Sˆ(x) that interpolates f(x) at the given points. Find Sˆ 0(x) and Sˆ 1(x), and verify that Sˆ (k) 0 (x1) = Sˆ (k) 1 (x1) for k = 0, 1, 2, 3. (e) Compare f(x) and these three cubic splines on the same plot. For each method, compute the maximum error at points x = 0 : 0.001 : 1. (You may use MATLAB function ppval to evaluate a piecewise polynomial at different points.) Discuss the quality of the approximations. Which one is the most accurate and which is the least accurate? Explain the reason in your own words. 2. Consider f(x) = xe−6x , 0 ≤ x ≤ 1. (a) Write a MATLAB script file using spline (with the option of clampled spline) to interpolate this function at equidistant points xi = ih, i = 0, 1, · · · n, where h = 1/n. Generate data to complete the following table. For each grid spacing, obtain the actual (numerical) error enum(h) and compute the numerical order of accuracy α. Is α consistent with your expectation? Find the error bound for each grid spacing. Does the error bound provide a good estimation of the actual error? Attach your script file to the report. k nk hk |enum(hk)| αk |ebound(hk)| 1 4 1/4 — 2 8 1/8 3 16 1/16 4 32 1/32 5 64 1/64 Here, |enum(hk)| is defined as the maximum error evaluated at x = 0 : 0.001 : 1, for the piecewise interpolating polynomial phk (x) with grid spacing hk: |enum(hk)| = max x=0:0.001:1 |f(x) − phk (x)|. The order of accuarcy α is a number such that the error e(h) = O(h α). The numerical order can be obtained from αk = ln(|enum(hk)|/|enum(hk−1)|) ln(hk/hk−1) . 1 (b) Repeat (a) using piecewise linear interpolation. You may use interp1 with method=‘linear’. 2

## Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

function Question2()

%clamped spline has endtype 2

%f(x)=x e^(-6x)   f'(x)=(1-6x)e^(-6x)
%f''(x)=(-12+36x)e^(-6x)

f=@(x)(x.* exp(-6*x));   df=@(x)((1-6*x).*exp(-6*x));
endtype=2;
h=zeros(1,5);
enum=zeros(1,5);%vector of errors
alpha=zeros(1,5);%vector of orders of precision
X=0:0.001:1;
for k=1:5
n=2^k;
h(k)=1/n;
x=0:h(k):1;
Y2=[df(0),f(x),df(1)];
[pp2]=myspline(x,Y2,endtype);
[breaks2, coefs2]=unmkpp(pp2);
enum(k)=max(abs(ppval(pp2,X)-f(X)));
end

for k=2:5
alpha(k)=log(enum(k)/enum(k-1))/log(h(k)/h(k-1));
end
EnumClampedSpline=enum
alphaClampedSpline=alpha...
\$85.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available Numerical Analysis Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.