cubic_interpolation

# cubic_interpolation - xr=bisection2(func,0,8,.00001,100);...

This preview shows page 1. Sign up to view the full content.

function cubic_interpolation(x,y,z) %Problem 15.5 %Inverse interpolation using a cubic interpolating polynomial and bisection %to determine the value of x that corresponds to f(x)=z for the data x,y %passed into the function cubic_interpolation. % %Since were calculating a cubic polynomial, we need to pick four points %degree=(n-1). The four points must be somewhere in the range of the value z %were trying to determine. plot(x,y,'o m'); grid hold on P=polyfit(x,y,3); %Finds coeff of 3rd degree polynomial P(4)=a0. ..ect func=@(x) P(4)-z+P(3)*x+P(2)*x^2+P(1)*x^3; %creates and anonymous function
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: xr=bisection2(func,0,8,.00001,100); %Inverse interpolation, this function, bisection2 finds %where the func crosses x axis. fprintf('\nf(x)=%3.2fx^3+%2.1fx^2+%3.2fx+%2.1f\n',P(1),P(2),P(3),P(4)); fprintf('x=%5.4f\n\n',xr); xx=linspace(min(x),max(x),50); y2=P(4)+P(3).*xx+P(2).*xx.^2+P(1).*xx.^3; plot(xx,y2,xr,z,'o'); title('Inverse Interpolation'); legend('tabulated data','cubic func','interpolated value'); ylabel('f(x)'); xlabel('x'); hold off pause y3=P(4)-z+P(3).*xx+P(2).*xx.^2+P(1).*xx.^3; plot(xx,y3,xr,0,'o') title('root finding graph') xlabel(' grid...
View Full Document

Ask a homework question - tutors are online