Xo = -1;%first x Xl = 1;%second x Yo = 0;%first y, y is a function of x Yl = 0;% second y, y is a function of x for x = -2:1:2 P = (Yo*(Xl-x)+(x-Xo)*Yl)/(Xl-Xo)%linear interpolation y = 0%actual value E = y-P%error hold on plot(x, E, 'r:+') end Xs = 0;%third x Ys = 0;%third y for x = -2:1:2 Lo = (X-Xl)*(X-Xs)/(Xo-Xl)*(Xo-Xs);%L0 Ll = (X-Xo)*(X-Xs)/(Xl-Xo)*(Xl-Xs);%L1 Ls = (X-Xo)*(X-Xl)/(Xs-Xo)*(Xs-Xl);%L2 P = Yo*Lo + Yl*Ll + Ys*Ls%quadratic interpolation y=0%actual value E=y-P%error end