This is for Numerical Mathematics course and they need the computer or math code
ID: 3184124 • Letter: T
Question
This is for Numerical Mathematics course and they need the computer or math code to attached for this project.
. Prepare a code implementing Lagrange's approximating polynomial Pix) for function y = f(x) on the interval [a, bl using n + 1 equally spaced nodes 20 = a, zl,....-m that you can change the finction = f(a), the interval la,, and the number of equally spaced interpolation nodes n, easily. Do the programing so that you can graph f(r), P( in one figure, and f() - Sx 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 numbcr of cqually spaced intcrpolation nodes n, casily. Do tho programming so that you can graph f(r), S(x) in one figure, and f() S(r) in another figure. (You can use Algorithm 3.4 on page 142) . Por y = cos(8:r) on [0,1] determine experi!nentally how many in- to approximatc the function within tcrpolation nodes arc nccded 10-5 using Lagrange interpolation polynomial and the natural c- bic spline. Plot f(r), P(z), and S(x) and also x) - P() and f(x) - St:)|. Which method reqs ore nodes to approximate ycosmr) within provided bounds? . For y = Vz.x2 on (0,1] determine cxporimentally how many in- terpolation nodes are needed to approximate the function within 10-5 using Lagrange interpolation polynomial and the natural cu- bic spline. Plot f(x), P(x), and S() and also |f(z) - P() and f(x) S(x)l. Which method requires more nodes to approximate y-Va-2 within provided bounds? Use both P(r) and S(r) to approximate y - Vr - 2 within 10-5 Which methods requires more nodes to approximate this function within the provided bounds? Plot f(z), P(x), and S() and also f(x) - P() and If(x) - S(x)l. Does error behaves similarly or differently for the two methods. Where the largest errors occur in both cascs? Col npare the properties of errr for both examples: y-cos(8TI) and y = V1-17. Do you observe any similarities or differences in the behavior of error. What happens as the nuber of nodes is changed from 10 to 20 to 40 to 80 to 160 in both methods, if you can Can you explain the similarities and/or differences using theorems from Chapter 3 » Write a report. Include results of your experiments. Please include graphs of f(x), P(), and S() and also f(x) - Pix)l and |f(x) S(z). You may usc tables to summarize propcrtics of crror. Includo you comments and explanations of observed facts. Attach the code.Explanation / 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')
%% the codes are replicable for each problem.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.