(I ONLY NEED PART 2) Can you use MATLAB for part 2 of the question please. (NO W
ID: 3282529 • Letter: #
Question
(I ONLY NEED PART 2) Can you use MATLAB for part 2 of the question please. (NO WRITTEN WORK)
(Algorith 3.4 is the Natural Cubic Spline just FYI)
Problem Anlais of performance of the cuble spline . Prepare a code implementing Lagrange's approximating polynomial P(x) for function y- f(z) on the interval la, b] using n +1 equally spaced nodes zo a, i,..nb. Keep the programming so that you can change the function y f(z), 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(z) in one figure, and f(x) S()] in another figure. Make sure you use plenty of points when you graph sot that the graphs appear smooth. . Prepare a code implementing the cubic spline S(a) 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(z) in one figure, and If(a) - S(a)| in another figure. (You can use Algorithm 3.4 on page 142)Explanation / Answer
-
-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,:);
-- 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')
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.