Изучение математического пакета MatLab, решение задачи интерполирования, страница 5

        axis([xmin, xmax, ymin, ymax]);

        crp=ravnomer(xmin,xmax,n(i));

        ctp=tcebishev(xmin,xmax,n(i));

        plot(x,sfunc(x),'--b','LineWidth',2)

        plot(x,lagranzh(x,crp),'-r','LineWidth',2)

        plot(x,lagranzh(x,ctp),'-g','LineWidth',2)

        %узлы

        plot(crp,sfunc(crp),'LineStyle','none','Marker','o',

'MarkerEdgeColor','k','MarkerFaceColor','r')

        plot(ctp,sfunc(ctp),'LineStyle','none','Marker','s',

'MarkerEdgeColor','k','MarkerFaceColor','g')

        legend('initial function','Lagranzh (evenly deviding)',

'Lagranzh (Tchebishev)',2)

    if (i~=3)

     subplot(1,2,2);

        hold all

        grid on

        axis auto

        title({['discrepancy for the polynom of the ',

int2str(n(i)),' order'];['(',int2str((n(i)+1)),' points)']});

        plot(x,(sfunc(x)-lagranzh(x,crp)),'-r','LineWidth',2)

        plot(x,(sfunc(x)-lagranzh(x,ctp)),'-g','LineWidth',2)

        plot(crp,0,'LineStyle','none','Marker','o','MarkerEdgeColor','k',

'MarkerFaceColor','r')

        plot(ctp,0,'LineStyle','none','Marker','s','MarkerEdgeColor','k',

'MarkerFaceColor','g')

        legend('Lagranzh (evenly deviding)','Lagranzh (Tchebishev)',2)

    else

     subplot(2,2,2);

        hold all

        grid on

        axis auto

        title({['discrepancy for the polynom of the ',

int2str(n(i)),' order'];['(',int2str((n(i)+1)),' points)']});

        plot(x,(sfunc(x)-lagranzh(x,crp)),'-r','LineWidth',2)

        plot(crp,0,'LineStyle','none','Marker','o','MarkerEdgeColor','k',

'MarkerFaceColor','r')

        legend('Lagranzh (evenly deviding)',2)

     subplot(2,2,4);

        hold all

        grid on

        axis auto

        plot(x,(sfunc(x)-lagranzh(x,ctp)),'-g','LineWidth',2)

        plot(ctp,0,'LineStyle','none','Marker','s','MarkerEdgeColor','k',

'MarkerFaceColor','g')

        legend('Lagranzh (Tchebishev)',2)

    end

end

sfunc.m

%sfunc возвращает заначения функции f(x)=0, x<0; f(x)=x, x>=0