% Example 10-2: Interpolation x = 0:1.0:5; y = [1.0 -0.6242 -1.4707 3.2406 -0.7366 -6.3717]; xi = 0:0.1:5; yilin = interp1(x, y, xi, 'linear'); yispl = interp1(x, y, xi, 'spline'); yipch = interp1(x, y, xi, 'pchip'); yfun = 1.5.^xi.*cos(2*xi); subplot(1,3,1) plot(x, y, 'o', xi, yfun, xi, yilin, '--'); title('Linear') subplot(1,3,2) plot(x, y, 'o', xi, yfun, xi, yispl, '--'); title('Cubic spline') subplot(1,3,3) plot(x, y, 'o', xi, yfun, xi, yipch, '--'); title('Pchip') pause clf