function polyinvert hold off % Original polynomial interpolation x = linspace(1,101,11)' y = 1./x plot(x,y,'kx') 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-',x1,y1,'r-') 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') 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-',y2,x2,'r-') legend('Inverted points','Inverted curve','Polynomial fit') pause hold off % Original problem repeated but with cubic spline interpolation added x = linspace(1,101,11)' y = 1./x plot(x,y,'kx') 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-',x1,y1,'r-',x1,y2,'b-') 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') legend('Inverted points') hold on y2 = linspace(min(y),max(y),100); x2 = spline(y,x,y2); x = 1./y2; plot(y2,x,'k-',y2,x2,'b-') legend('Inverted points','Inverted curve','Cubic spline fit')