Question

Consider the function f(x) 1 25x which is used to test various interpolation methods. For the remainder of this problem consi

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

script file to plot figure using matlab

figPlotUsingMtlb.m

% base points/knots used
xData=-1:0.25:1;
yData=1./(1+25*xData.^2);

% 1001 sample points
xVal=-1:0.002:1;
fx=1./(1+25*xVal.^2);
for i=1:6
subplot(2,3,i), plot(xVal,fx,'-k','Linewidth',2); hold on
subplot(2,3,i), plot(xData,yData,'.r','Markersize',25);
end

% using ployfit 4th order
P=polyfit(xData,yData,4);
y_polyfit4=P(1)*xVal.^4+P(2)*xVal.^3+P(3)*xVal.^2+P(4)*xVal+P(5);
subplot(2,3,1),plot(xVal,y_polyfit4,'-b','Linewidth',6); hold on

% using ployfit 8th order
P=polyfit(xData,yData,8);
y_polyfit8=P(1)*xVal.^8+P(2)*xVal.^7+P(3)*xVal.^6+P(4)*xVal.^5+...
P(5)*xVal.^4+P(6)*xVal.^3+P(7)*xVal.^2+P(8)*xVal+P(9);
subplot(2,3,2),plot(xVal,y_polyfit8,'-b','Linewidth',6); hold on

% linear interpolation using interp1 linear
x1=xData';
y1=yData';
xq=xVal';
y_linear = interp1(x1,y1,xq,'linear');
subplot(2,3,3),plot(xVal,y_linear,'-b','Linewidth',6); hold on

% interpolation using interp1 nearest
y_nearest = interp1(x1,y1,xq,'nearest');
subplot(2,3,4),plot(xVal,y_nearest,'-b','Linewidth',6); hold on

% interpolation using interp1 spline
y_spline = interp1(x1,y1,xq,'spline');
subplot(2,3,5),plot(xVal,y_spline,'-b','Linewidth',6);

% interpolation using interp1 makima
% Version of Matlab is : MATLAB R2015a

shg
subplot(2,3,1)
title('First Subplot')
subplot(2,3,2)
title('Second Subplot')
subplot(2,3,3)
title('Third Subplot')
subplot(2,3,4)
title('Fourth Subplot')
subplot(2,3,5)
title('Fifth Subplot')
subplot(2,3,6)
title('sixth Subplot')

% will work if have MATLAB R2018a and latest versions of matlab
sgtitle('Figure(777)')

code end here

image of ploted figure

Second s Second Subplot Third Subplot 1st Subplot 0.5 0.5 0 0.5 -2 1 -1 1 -1 Fourth Subplot Fifth Subplot sixth Subplot 0.5 0

Add a comment
Know the answer?
Add Answer to:
Consider the function f(x) 1 25x which is used to test various interpolation methods. For the rem...
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
  • 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...

  • 1. Consider the Runge function, f:IH 1/1+25r). (a) Use your Lagrange interpolation code (from the...

    1. Consider the Runge function, f:IH 1/1+25r). (a) Use your Lagrange interpolation code (from the previous worksheets) to approximate f using 10, 20, 30, and 40 equispaced points from -1 and 1 (inclusive). Make a (single) plot comparing these four approximations with the (exact) function f. Use a legend to help distinguish the five curves. Intuitively, increasing the number of sample points should give a 'better' approximation. Does it? (A qualitative answer is sufficient.) (b) Repeat Part (a) using piecewise...

  • 1. Numerical Integration The integral of a function f(x) for a s x S b can be interpreted as the ...

    1. Numerical Integration The integral of a function f(x) for a s x S b can be interpreted as the area between the f(x) curve and the x axis, bounded by the limits x- a and x b. If we denote this area by A, then we can write A as A-f(x)dx A sophisticated method to find the area under a curve is to split the area into trapezoidal elements. Each trapezoid is called a panel. 1.2 0.2 1.2 13...

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