Question
Please redo problem 1 ( MY CODE BELOW) but instead use the built-in MATLAB functions spline and ppval to build a clamped spline that solves
Please redo problem 1 (MY CODE BELOW) but instead use the built-in MATLAB functions spline and ppval to build a clamped spline that solves the problem. Here is an example script from Mathworks.com to get you started.
x=-4:4; y=[0 .15 1.12 2.36 2.36 1.46 .49 .06 0]; clamped=spline(x,[0 y 0]); xx=linspace(-4,4,101); plot(x,y,o,xx,ppval(clamped,xx),-);
Use 50 equispaced points for this problem.
MAT 340 NUMERICAL METHODS. THANKS IN ADVANCE!
f=@(x) 1./(1+10.*x.^2);
X=linspace(-1,1); %% domain in order to plot
%% s for the error
s=linspace(0,1);
plot(X,f(X),'k','lineWidth',3)
hold on
for n=3:12
x=linspace(-1,1,n+1);
y=f(x);
P=lagrangepoly(x,y);
plot(X,P(X),'--')
n
Error_n=max(abs(f(s)-P(s)))
end
%%
% The error was decreasing up until the odd n's up until 7 and increasing for even n's
% For n=100 the error should be large
1 Problem 1 For a set of n + 1 data points (^o, o), (x1,yi),..., (xn,yn) we want to approxi mate a given function f(x) by polynomial interpolation, i.e where each L(x) is a Lagrange polynomial defined by (x - xo)(x - xi)..-(x - x,-1)(x - ^iti)... (x - xn) Li(x) := i=0, 1, . . . , n. Write a function that finds the interpolating polynomials Pn(x), with n-3, 4, ,12 which 14m3 on x 1-1, 1]. Plot all polynomials Pn(x) and the function f(x) in the same figure. For each n, use approximate the function j(x) 1+10x Error, - max) xE[0,1 to measure the error. What do you observe? What would you predict if n 100? 1 Problem 1 For a set of n + 1 data points (^o, o), (x1,yi),..., (xn,yn) we want to approxi mate a given function f(x) by polynomial interpolation, i.e where each L(x) is a Lagrange polynomial defined by (x - xo)(x - xi)..-(x - x,-1)(x - ^iti)... (x - xn) Li(x) := i=0, 1, . . . , n. Write a function that finds the interpolating polynomials Pn(x), with n-3, 4, ,12 which 14m3 on x 1-1, 1]. Plot all polynomials Pn(x) and the function f(x) in the same figure. For each n, use approximate the function j(x) 1+10x Error, - max) xE[0,1 to measure the error. What do you observe? What would you predict if n 100Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started