Question

In: Advanced Math

Consider polynomial interpolation of the function f(x)=1/(1+25x^2) on the interval [-1,1] by (1) an interpolating polynomial...

Consider polynomial interpolation of the function f(x)=1/(1+25x^2) on the interval [-1,1] by (1) an interpolating polynomial determined by m equidistant interpolation points, (2) an interpolating polynomial determined by interpolation at the m zeros of the Chebyshev polynomial T_m(x), and (3) by interpolating by cubic splines instead of by a polynomial. Estimate the approximation error by evaluation max_i |f(z_i)-p(z_i)| for many points z_i on [-1,1]. For instance, you could use 10m points z_i. The cubic spline interpolant can be determined in MATLAB; see "help spline". Use m=10 and m=20. Compute splines that interpolate at equidistant nodes and at Chebyshev nodes. Provide tables of the errors and plots of the function f and the interpolating polynomials and splines.

Solutions

Expert Solution


%%Matlab function for Lagrange Interpolation
clear all
close all
%first function
f1=@(x) 1./(1+25.*x.^2);
%loop for Lagrange polynomial for all n
a=-1;b=1; k=0;
for n=10:10:20
    k=k+1;
    %Equidistance data points
    x1=linspace(a,b,n);
    y1=double(f1(x1));
  
    %Chebyshev data points
    for i=1:n
        x2(i)=(1/2)*(a+b)+(1/2)*(b-a)*cos(((2*i-1)*pi)/(2*n));
    end

    y2=double(f1(x1));
  
  
    syms x
    %x1=independent variable;y1=dependent variable;x=value at which we have to
    %find the dependent variable;y=corresponding value of dependent variable at x;
    p1=polyfit(x1,y1,n-1);
    p2=polyfit(x2,y2,n-1);
  
    %the interpolated data polyfit
    xx1=linspace(a,b,200);
    %polynomial fit for Equidistance points
    yy1=polyval(p1,xx1);
    %polynomial fit for Chebyshev points
    yy2=polyval(p2,xx1);
    %cubic spline
    yy3_eq=spline(x1,y1,xx1);
    yy3_ch=spline(x2,y2,xx1);
  
    %plotting of function
        figure(k)
        hold on
        plot(xx1,yy1,'Linewidth',2)
        plot(xx1,yy2,'Linewidth',2)
        plot(xx1,yy3_eq,'Linewidth',2)
        plot(xx1,yy3_ch,'Linewidth',2)
        plot(xx1,f1(xx1),'Linewidth',2)
      
        xlabel('x')
        ylabel('f(x)')
        legend('Equidistance','Chebyshev','Spline equidistance','Spline equidistance','Actual')
        title(sprintf('Interpolating polynomial for n=%d',n))
  
        fprintf('\tError in Equidistance interpolation for n=%d is %e.\n',n,norm(yy1-f1(xx1)))
        fprintf('\tError in Chebyshev interpolation for n=%d is %e.\n',n,norm(yy2-f1(xx1)))
        fprintf('\tError in Equidistance spline interpolation for n=%d is %e.\n',n,norm(yy3_eq-f1(xx1)))
        fprintf('\tError in Chebyshev spline interpolation for n=%d is %e.\n\n',n,norm(yy3_ch-f1(xx1)))
      


end


               %%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%%

%----------------------------------------------------------------%


Related Solutions

On the interval [-1,1], consider interpolating Runge’s function f(x) = 1/ (1 + 25x^2) By Pn(x),...
On the interval [-1,1], consider interpolating Runge’s function f(x) = 1/ (1 + 25x^2) By Pn(x), use computer to graph: (c) Take 11 equally spaced nodes in [-1,1], starting at –1, ending at 1, and obtain the interpolating polynomial P10(x). Also, use 11 Chebyshev nodes in [-1,1] and obtain Pc(x), the corresponding interpolating polynomial. In the same graph, plot the three functions f(x), P10(x) and Pc(x) over the interval [-1,1] . Use different line-styles, so that f(x), P10(x) and Pc(x)...
Find the Chebyshev interpolation nodes on the interval [4,12] for an interpolating polynomial of degree 5
Find the Chebyshev interpolation nodes on the interval [4,12] for an interpolating polynomial of degree 5
Use the Lagrange interpolating polynomial to approximate √3 with the function f(x)= 3x-0.181and the values x0=-2,...
Use the Lagrange interpolating polynomial to approximate √3 with the function f(x)= 3x-0.181and the values x0=-2, X1=-1, X2=0, X3=1 and X4=2.(Uses 4 decimal figures)
Compute the quartic interpolating polynomial for the Hermite interpolation problem p(0) = 2, p'(0) = -9...
Compute the quartic interpolating polynomial for the Hermite interpolation problem p(0) = 2, p'(0) = -9 p(1) = -4, p'(1) = 4 p(2) = 44 with respect to the Newton basis. Compute the divided differences. Find a quintic interpolating polynomial that additionally satisfies p(3) = 2.
the function F:(-1,1)toR dfined by F(x)=x/(1-x^2) is homeomorphism in a topology.. please explain the answer for...
the function F:(-1,1)toR dfined by F(x)=x/(1-x^2) is homeomorphism in a topology.. please explain the answer for me
Find the Taylor polynomial of degree 2 centered at a = 1 for the function f(x)...
Find the Taylor polynomial of degree 2 centered at a = 1 for the function f(x) = e^(2x) . Use Taylor’s Inequality to estimate the accuracy of the approximation e^(2x) ≈ T2(x) when 0.7 ≤ x ≤ 1.3
Consider the function f(x)= x3 x2 − 1 Express the domain of the function in interval...
Consider the function f(x)= x3 x2 − 1 Express the domain of the function in interval notation: Find the y-intercept: y=   . Find all the x-intercepts (enter your answer as a comma-separated list): x=   . On which intervals is the function positive?   On which intervals is the function negative?   Does f have any symmetries? f is even;f is odd;     f is periodic;None of the above. Find all the asymptotes of f (enter your answers as equations): Vertical asymptote (left):   ; Vertical...
Consider the function on the interval (0, 2π). f(x) = sin(x)/ 2 + (cos(x))^2 (a) Find...
Consider the function on the interval (0, 2π). f(x) = sin(x)/ 2 + (cos(x))^2 (a) Find the open intervals on which the function is increasing or decreasing. (Enter your answers using interval notation.) increasing decreasing (b) Apply the First Derivative Test to identify the relative extrema. relative maximum (x, y) = relative minimum (x, y) =
Find the lagrange polynomials that approximate f(x) = x3 a ) Find the linear interpolation polynomial...
Find the lagrange polynomials that approximate f(x) = x3 a ) Find the linear interpolation polynomial P1(x) using the nodes x0= -1 and x1 = 0 b) Find the quadratic interpolation polynomial P2(x) using the nodes x0= -1 and x1 = 0 and x2 = 1 c) Find the cubic interpolation polynomial P3(x) using the nodes x0= -1 and x1 = 0 and x2 = 1 and x3=2 d) Find the linear interpolation polynomial P1(x) using the nodes x0= 1...
Using Matlab, consider the function f(x) = x^3 – 2x + 4 on the interval [-2,...
Using Matlab, consider the function f(x) = x^3 – 2x + 4 on the interval [-2, 2] with h = 0.25. Write the MATLAB function file to find the first derivatives in the entire interval by all three methods i.e., forward, backward, and centered finite difference approximations. Could you please add the copiable Matlab code and the associated screenshots? Thank you!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT