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

Coding project in numerical analysis. If anything, just write the code and expla

ID: 3282531 • Letter: C

Question

Coding project in numerical analysis. If anything, just write the code and explain how to use it with each problem.

Problem 1: Analysis of performance of the cubic spline » Prepare a code implementing Lagrange's approximating polynomial P() for function y - f(x) on the interval [a, b] using n 1 equally spaced nodes x0-a,x1, ,an that you can change the function y -f(x), the interval [a, b], and the number of equally spaced interpolation nodes n, easily. Do the programming so that you can graph f(x), P(x) in one figure, and f (x) S(x)| in another figure. Make sure you use plenty of points when you graph sot that the graphs appear smooth b. Keep the programming so » Prepare a code implementing the cubic spline S(x) with natural boundary conditions (S" (a) - S"(b)- 0). Keep you programming so that you can change the function y - f(x), the interval [a, b], and the number of equally spaced interpolation nodes n, easily. Do the programming so that you can graph f(x), S(x) in one figure, and f(z) - S(x)| in another figure. (You can use Algorithm 3.4 on page 142) . For y cos(8Tz) on [0, 1] determine experimentally how many in terpolation nodes are needed to approximate the function within 10- using Lagrange interpolation polynomial and the natural cu- bic spline. Plot f(), P(x), and S(x) and also |f(x) - P(x and f (x) S(x)|. Which method requires more nodes to approximate y-cos(8??) within provided bounds? For y VT-2,2 on [O,1] determine experimentally how many In terpolation nodes are needed to approximate the function within 10-" using Lagrange interpolation polynomial and the natural cu- bic spline. Plot f(x), P(x), and S(x) and also |f(x) - P(x and f (a) - S(x)|. Which method requires more nodes to approximate y- Vr - a2 within provided bounds? . Use both P(x) and S(x) to approximate y- Vx - x2 within 10- Which methods requires more nodes to approximate this function within the provided bounds? Plot f(x), P(x), and S(x) and also f (a) - P(x)| and |f (a) - S(x)|. Does error behaves similarly or differently for the two methods. Where the largest errors occur in both cases?

Explanation / Answer

Solution:

1st question answer

For lagrange interpolation

-LAGRANGE(X,POINTX,POINTY) approx the function definited by the points:

- P1=(POINTX(1),POINTY(1)), P2=(POINTX(2),POINTY(2)), ..., PN(POINTX(N),POINTY(N))

n=size(pointx,2);

L=ones(n,size(x,2));

if (size(pointx,2)~=size(pointy,2))

fprintf(1,' ERROR! POINTX and POINTY must have the same number of elements ');

y=NaN;

else

for i=1:n

for j=1:n

if (i~=j)

L(i,:)=L(i,:).*(x-pointx(j))/(pointx(i)-pointx(j));

end

end

end

y=0;

for i=1:n

y=y+pointy(i)*L(i,:);

end

end

-- for natural cubic spline

pp = csape(x,YOUR FUNCTION VALUES,'second');

plot(xx, fnval(pp,xx) - YOUR FUNCTION VALUES)

title('Error in ''Natural'' Spline Interpolation to (YOUR FUNCTION')

Please post rest of the questions seperatley. Thanks!