gusucode.com > Matlab精彩编程100例源码程序 > Matlab精彩编程100例源码/work/shili87.m

    h0=figure('toolbar','none',...
    'position',[200 50 350 450],...
    'name','实例87');
h1=axes('parent',h0,...
    'position',[0.10 0.45 0.8 0.5],...
    'visible','off');
x=0:0.2:2*pi;
y=sin(x);
plot(x,y)
b1=uicontrol('parent',h0,...
    'units','points',...
    'tag','b1',...
    'style','pushbutton',...
    'string','牛顿插值',...
    'backgroundcolor',[0.75 0.75 0.75],...
    'position',[20 60 70 20],...
    'callback',[...
        'strn=get(e1,''string'');,',...
        'n=str2num(strn);,',...
        'x=0:0.2:2*pi;,',...
        'i=1;,',...
        'for t=0:0.2:2*pi,',...
        'y(i)=sin(t);,',...
        'ynt(i)=newton(t,n);,',...
        'i=i+1;,',...
        'end,',...
        'plot(x,y,''b*'',x,ynt,''r-''),',...
        'axis([0 7 -1.5 1.5]),',...
        'legend(''sin(x)'',''牛顿插值'')']);
b2=uicontrol('parent',h0,...
    'units','points',...
    'tag','b2',...
    'style','pushbutton',...
    'string','误差比较',...
    'backgroundcolor',[0.75 0.75 0.75],...
    'position',[170 60 70 20],...
    'callback',[...
        'strn=get(e1,''string'');,',...
        'n=str2num(strn);,',...
        'strdn=get(e2,''string'');,',...
        'dn=str2num(strdn);,',...
        'dd=abs(sin(dn)-newton(dn,n));,',...
        'msgbox([''误差为:'',num2str(dd)],''计算结果'')']);
e1=uicontrol('parent',h0,...
    'units','points',...
    'tag','e1',...
    'style','edit',...
    'fontsize',12,...
    'string','5',...
    'horizontalalignment','right',...
    'backgroundcolor',[1 1 1],...
    'position',[50 100 40 20]);
e2=uicontrol('parent',h0,...
    'units','points',...
    'tag','e2',...
    'style','edit',...
    'fontsize',12,...
    'string','1.20',...
    'horizontalalignment','right',...
    'backgroundcolor',[1 1 1],...
    'position',[200 100 40 20]);
t1=uicontrol('parent',h0,...
    'units','points',...
    'tag','t1',...
    'style','text',...
    'string','节点数:(<6)',...
    'fontsize',12,...
    'backgroundcolor',[0.75 0.75 0.75],...
    'position',[10 100 40 30]);
t2=uicontrol('parent',h0,...
    'units','points',...
    'tag','t2',...
    'style','text',...
    'string','误差点:',...
    'fontsize',12,...
    'backgroundcolor',[0.75 0.75 0.75],...
    'position',[160 100 40 20]);
b3=uicontrol('parent',h0,...
    'units','points',...
    'tag','b3',...
    'style','pushbutton',...
    'string','关闭',...
    'backgroundcolor',[0.75 0.75 0.75],...
    'position',[100 20 60 20],...
    'callback','close');