## Exploring Interpolation

\% Interpolation examples

\% Choose Number of points to play with:

Number=10;

t=linspace(.2,2.3,Number)

y=1./t+t.$\hat{\ }$2

a=polyfit(t,y,Number-1)

x=linspace(.2,2.3,100);

f=1./x+x.$\hat{\ }$ 2;

ftilde=polyval(a,x);

plot(x,f,'r',x,ftilde,'g',t,y,'mo')

\% Shows Function, interpolation and dots on the same plot

\% Try unequal spaced points, result is strange

t=[.2 .3 .5 .6 1.6 2.3]

y=1./t+t.$\hat{\ }$ 2

a=polyfit(t,y,Number-1)

x=linspace(.2,2.3,100);

f=1./x+x.$\hat{\ }$ 2;

ftilde=polyval(a,x);

plot(x,f,'r',x,ftilde,'g',t,y,'mo')

Number=20;

\% This is the classical example producing wiggles

t=linspace(-1,1,Number);

\% t=-cos((2*(1:Number)-1)*pi./(2*Number));

\% Uncomment the preveous  line for C. points

y=1./ (1+25* t.$\hat{\ }$ 2);

a=polyfit(t,y,Number-1);

x=linspace(-1,1,200);

f=1./(1+25*x.$\hat{\ }$ 2);

ftilde=polyval(a,x);

plot(x,f,'r',x,ftilde,'g',t,y,'mo')

\% Do the same with SPLINE interpolation

y = 1./(1+25*x.$\hat{\ }$ 2);