Question
USE NEWTON'S DIVIDED DIFFERENCES INSTEAD OF LAGRANGE FOR MY MATLAB CODE PLEASE, MAT 340 NUMERICAL METHODS. THANKS IN ADVANCE! MY CODE: PLEASE CHANGE IT TO
USE NEWTON'S DIVIDED DIFFERENCES
INSTEAD OF
LAGRANGE FOR MY MATLAB CODE PLEASE,
MAT 340 NUMERICAL METHODS. THANKS IN ADVANCE!
MY CODE: PLEASE CHANGE IT TO INSTEAD USE NEWTON'S DIVIDED DIFFERENCES to construct the interpolating polynomial. Your Newton interpolating function must have the coordinates and the domain you are interpolating over and output the polynomial along with its maximum error defined. Provide plots.
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