% Construct a circle t = linspace(0,4); x = cos(pi*t/2); y = sin(pi*t/2); T = [0 1 2 3 4]; X = cos(pi*T/2); Y = sin(pi*T/2); plot(t,x,t,y,T,X,'o',T,Y,'o'), axis('equal'),grid on pause plot(x,y,X,Y,'o'), axis('equal'), grid on pause % polynomial interpolation a = polyfit(T,X,4); b = polyfit(T,Y,4); p = polyval(a,t); q = polyval(b,t); plot(t,x,t,y,t,p,t,q,T,X,'o',T,Y,'o'), axis('equal'),grid on pause plot(x,y,X,Y,'o',p,q), axis('equal'), grid on pause % polynomial interpolation 2 T = [0.2 1 2 3 3.8]; X = cos(pi*T/2); Y = sin(pi*T/2); a = polyfit(T,X,4); b = polyfit(T,Y,4); p = polyval(a,t); q = polyval(b,t); plot(t,x,t,y,t,p,t,q,T,X,'o',T,Y,'o'), axis('equal'),grid on pause plot(x,y,X,Y,'o',p,q), axis('equal'), grid on pause % Hermite T = [0 1 2 3 4]; X = cos(pi*T/2); Y = sin(pi*T/2); SX = -pi*Y/2; SY = pi*X/2; a = pwch(T,X,SX); b = pwch(T,Y,SY); p = ppval(a,t); q = ppval(b,t); plot(t,x,t,y,t,p,t,q,T,X,'o',T,Y,'o'), axis('equal'),grid on pause plot(x,y,X,Y,'o',p,q), axis('equal'), grid on pause % Not a knot a = spline(T,X); b = spline(T,Y); p = ppval(a,t); q = ppval(b,t); plot(t,x,t,y,t,p,t,q,T,X,'o',T,Y,'o'), axis('equal'),grid on pause plot(x,y,X,Y,'o',p,q), axis('equal'), grid on pause % clamped spline SX = [ 0 X 0]; SY = [pi/2 Y pi/2]; a = spline(T,SX); b = spline(T,SY); p = ppval(a,t); q = ppval(b,t); plot(t,x,t,y,t,p,t,q,T,X,'o',T,Y,'o'), axis('equal'),grid on pause plot(x,y,X,Y,'o',p,q), axis('equal'), grid on pause % shape preserver a = pchip(T,X); b = pchip(T,Y); p = ppval(a,t); q = ppval(b,t); plot(t,x,t,y,t,p,t,q,T,X,'o',T,Y,'o'), axis('equal'),grid on pause plot(x,y,X,Y,'o',p,q), axis('equal'), grid on