Question

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

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1


Matlab function for Lagrange Interpolation clear all close all %first function %loop for Lagrange polynomial for all n for n-n,n,norm (yyl-fl (xxl))) n,n,norm (yy2-f1 (xx1))) is %e .\n,n,norm(yy3_eq-f1(xx 1))) e. Inin,n, norm(yy3_ch-fl (xxl))) titInterpolating polynomial for n-10 Equidistance Chebyshev Spline equidistance Spline equidistance 0.8 -Actual 0.6 0.4 0.2 -0.2

%%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 %%%%%%%%%%%%%%%%%%%

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

Add a comment
Know the answer?
Add Answer to:
Consider polynomial interpolation of the function f(x)=1/(1+25x^2) on the interval [-1,1] by (1) ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a python program that plots a given function and an interpolation polynomial. To test this,...

    programming in python. Write a python program that plots a given function and an interpolation polynomial. To test this, use the following cases: a) )xp(-4r2), tE-1,1]. As data, use equidistant nodes that include the endpoints and the function values in those nodes. The number of nodes should be 5, then 12. Write a python program that plots a given function and an interpolation polynomial. To test this, use the following cases: a) )xp(-4r2), tE-1,1]. As data, use equidistant nodes that...

  • programming in python. Write a python program that plots a given function and an interpolation polynomial....

    programming in python. Write a python program that plots a given function and an interpolation polynomial. To test this, use the following cases: a) )xp(-4r2), tE-1,1]. As data, use equidistant nodes that include the endpoints and the function values in those nodes. The number of nodes should be 5, then 12.

  • Consider the function f(x) 1 25x which is used to test various interpolation methods. For the rem...

    Consider the function f(x) 1 25x which is used to test various interpolation methods. For the remainder of this problem consider only the interval [-1, 1] The x-values for the knots (or base-points) of the interpolation algorithm are located at x--1,-0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75 1. (a) Create a "single" figure in Matlab that contains 6 subplots (2x3) and is labelled as figure (777), i.e the figure number is 777. Plot in each subplot the function f(x) using...

  • Problem 1: Recall that the Chebyshev nodes 20, 21, ...,.are determined on the interval (-1,1) as...

    Problem 1: Recall that the Chebyshev nodes 20, 21, ...,.are determined on the interval (-1,1) as the zeros of Tn+1(x) cos((n + 1) arccos(x)) and are given by 2; +17 Tj = COS , j = 0,1,...n. n+1 2 Consider now interpolating the function f(x) = 1/(1 + x2) on the interval (-5,5). We have seen in lecture that if equispaced nodes are used, the error grows unbound- edly as more points are used. The purpose of this problem is...

  • 2. Consider interpolating the data (x0,yo), . . . , (x64%) given by Xi | 0.1...

    2. Consider interpolating the data (x0,yo), . . . , (x64%) given by Xi | 0.1 | 0.15 | 0.2 | 0.3 | 0.35 | 0.5 | 0.75 yi 4.0 1.0 1.22.12.02.52.5 For all tasks below, please submit your MATLAB code and your plots. You can write all code in a single (a) Using MATLAB, plot the interpolating (6th degree) polynomial given these data on the domain .m-file [0.1,0.75] using the polyfit and polyval commands. To learn how to use...

  • Question 1 2 pts The Hermite Interpolation polynomial for 33 distinct nodes has Degree at most...

    Question 1 2 pts The Hermite Interpolation polynomial for 33 distinct nodes has Degree at most {Be Careful with the answer. Look at the Theorem and the Question Carefully; compare the given information} Question 2 2 pts If f € C4 [a, b] and p1, P2, P3, and p4 are Distinct Points in [a, b], Then 1. There are two 3rd divided differences 2. There is exactly one 3rd divided difference and it is equal to the value of f(iv)...

  • Problem 6: Interpolation, least squares, and finite difference Consider the following data table: 2 = 0...

    Problem 6: Interpolation, least squares, and finite difference Consider the following data table: 2 = 0 0.2 0.4 0.6 f(x) = 2 2.018 2.104 2.306 A cubic spline interpolation over these data is constructed as a cubic polynomial interpolating over all 4 data points. None of the above. is constructed by piece-wise locally cubic polynomial interpolation that maintains continuity of the first and second derivatives at the data points is constructed by plece-wise locally cubic polynomial interpolation that has discontinuous...

  • 1. Runge's function is written as f(x) = 1 25r2 (a) Develop a plot of this function for the inter...

    1. Runge's function is written as f(x) = 1 25r2 (a) Develop a plot of this function for the interval from x =-1 to 1 using Matlab (no submission required). Develop the fourth-order Lagrange interpolating polynomial using equispaced function values corresponding to xi =-1,-0.5, 0, 0.5, and 1. (Note that you first need to determine the (a. ) pairs.) Use the polynomial to estimate f(0.9). (b) What is et? (c) Generate a cubic spline using the five data points from...

  • 1. Consider the polynonial Pl (z) of degree 4 interpolating the function f(x) sin(x) on the interval n/4,4 at the e...

    1. Consider the polynonial Pl (z) of degree 4 interpolating the function f(x) sin(x) on the interval n/4,4 at the equidistant points r--r/4, xi =-r/8, x2 = 0, 3 π/8, and x4 = π/4. Estimate the maximum of the interpolation absolute error for x E [-r/4, π/4 , ie, give an upper bound for this absolute error maxsin(x) P(x) s? Remark: you are not asked to give the interpolation polynomial P(r). 1. Consider the polynonial Pl (z) of degree 4...

  • This assignment is about polynomial interpolation. 1) The user should be able to enter: a. A...

    This assignment is about polynomial interpolation. 1) The user should be able to enter: a. A function named f. b. A number of points (nodes) with their respective values. c. A point x0 2) The output should be: a. A Newton Divided Differences polynomial (function of x) that approximates the function with agreement in the points. b. An approximation of f(x0) by Newton Divided Differences polynomial. c. The approximation absolute and relative errors.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT