polyinvert - x = linspace(1,101,11)' y = 1./x...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 function polyinvert close all hold off % Original polynomial interpolation x = linspace(1,101,11)' y = 1./x plot(x,y,'kx','LineWidth',2) legend('Original points') hold on pause p1 = polyfit(x,y,10) x1 = linspace(1,101,100) y1 = polyval(p1,x1) y = 1./x1 plot(x1,y,'k-','LineWidth',2) plot(x1,y1,'r-','LineWidth',2) legend('Original points','Original curve','Polynomial fit') pause hold off % Inverted polynomial interpolation x = linspace(1,101,11)' y = 1./x plot(y,x,'kx','LineWidth',2) legend('Inverted points') hold on pause p2 = polyfit(y,x,10) y2 = linspace(min(y),max(y),100) x2 = polyval(p2,y2) x = 1./y2 plot(y2,x,'k-','LineWidth',2) plot(y2,x2,'r-','LineWidth',2) legend('Inverted points','Inverted curve','Polynomial fit') pause hold off % Original problem repeated but with cubic spline interpolation added
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: x = linspace(1,101,11)' y = 1./x plot(x,y,'kx','LineWidth',2) legend('Original points') hold on p1 = polyfit(x,y,10) x1 = linspace(1,101,100) y1 = polyval(p1,x1) y2 = spline(x,y,x1) y = 1./x1 plot(x1,y,'k-','LineWidth',2) plot(x1,y1,'r-','LineWidth',2) Sheet1 Page 2 plot(x1,y2,'b-','LineWidth',2) legend('Original points','Original curve','Polynomial fit','Cubic spline fit') pause hold off % Inverted problem repeated but with cubic spline interpolation added x = linspace(1,101,11)' y = 1./x plot(y,x,'kx','LineWidth',2) legend('Inverted points') hold on y2 = linspace(min(y),max(y),100) x2 = spline(y,x,y2) x = 1./y2 plot(y2,x,'k-','LineWidth',2) plot(y2,x2,'b-','LineWidth',2) legend('Inverted points','Inverted curve','Cubic spline fit')...
View Full Document

Page1 / 2

polyinvert - x = linspace(1,101,11)' y = 1./x...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online