?? matlab實用程序百例3.txt
字號:
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',[...
'cla,',...
'strn=get(e1,''string'');,',...
'n=str2num(strn);,',...
'i=1;,',...
'x=0:0.2:2*pi;,',...
'for t=0:0.2:2*pi,',...
'y(i)=sin(t);,',...
'L(i)=lag(t,n);,',...
'i=i+1;,',...
'end,',...
'plot(x,y,''b*'',x,L,''r-''),',...
'legend(''sin(x)'',''插值函數'');,',...
'axis([0 7 -1.5 1.5])']);
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);,',...
'strm=get(e2,''string'');,',...
'm=str2num(strm);,',...
'dd=abs(sin(m)-lag(m,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','階數:',...
'fontsize',12,...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[20 100 30 20]);
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');
例86:三次樣條插值法
h0=figure('toolbar','none',...
'position',[200 50 350 450],...
'name','實例86');
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',[...
'y=0,',...
'sy=0,',...
'strn1=get(e2,''string'');,',...
'n1=str2num(strn1);,',...
'strn2=get(e3,''string'');,',...
'n2=str2num(strn2);,',...
'x=n1:0.2:n2;,',...
'i=1;,',...
'for t=n1:0.2:n2,',...
'y(i)=sin(t);,',...
'sy(i)=san(t,n1,n2);,',...
'i=i+1;,',...
'end,',...
'plot(x,y,''b*'',x,sy,''r-''),',...
'axis([0 7 -1.5 1.5]),',...
'legend(''sin(x)'',''N-Hermite插值'')']);
b2=uicontrol('parent',h0,...
'units','points',...
'tag','b2',...
'style','pushbutton',...
'string','誤差比較',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[170 60 70 20],...
'callback',[...
'strdn1=get(e2,''string'');,',...
'n1=str2num(strdn1);,',...
'strdn2=get(e3,''string'');,',...
'n2=str2num(strdn2);,',...
'strdn=get(e1,''string'');,',...
'dn=str2num(strdn);,',...
'dd=abs(sin(dn)-san(dn,n1,n2));,',...
'msgbox([''誤差為:'',num2str(dd)],''計算結果'')']);
e1=uicontrol('parent',h0,...
'units','points',...
'tag','e1',...
'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','誤差點:',...
'fontsize',12,...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[160 100 40 20]);
e2=uicontrol('parent',h0,...
'units','points',...
'tag','e2',...
'style','edit',...
'fontsize',12,...
'string','1.00',...
'horizontalalignment','right',...
'backgroundcolor',[1 1 1],...
'position',[20 85 40 20]);
t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','第一節點:',...
'fontsize',12,...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[15 105 50 20]);
e3=uicontrol('parent',h0,...
'units','points',...
'tag','e3',...
'style','edit',...
'fontsize',12,...
'string','3.00',...
'horizontalalignment','right',...
'backgroundcolor',[1 1 1],...
'position',[100 85 40 20]);
t3=uicontrol('parent',h0,...
'units','points',...
'tag','t3',...
'style','text',...
'string','第二節點:',...
'fontsize',12,...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[95 105 50 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');
實例87:NEWTON插值
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');
實例88:hermite插值
h0=figure('toolbar','none',...
'position',[200 50 350 450],...
'name','實例88');
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','Hermite插值',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[20 60 70 20],...
'callback',[...
'strn1=get(e2,''string'');,',...
'n1=str2num(strn1);,',...
'strn2=get(e3,''string'');,',...
'n2=str2num(strn2);,',...
'x=0:0.2:2*pi;,',...
'i=1;,',...
'for t=0:0.2:2*pi,',...
'y(i)=sin(t);,',...
'ynt(i)=hermite(t,n1,n2);,',...
'i=i+1;,',...
'end,',...
'plot(x,y,''b*'',x,ynt,''r-''),',...
'axis([0 7 -1.5 1.5]),',...
'legend(''sin(x)'',''Hermite插值'')']);
b2=uicontrol('parent',h0,...
'units','points',...
'tag','b2',...
'style','pushbutton',...
'string','誤差比較',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[170 60 70 20],...
'callback',[...
'strn1=get(e2,''string'');,',...
'n1=str2num(strn1);,',...
'strn2=get(e3,''string'');,',...
'n2=str2num(strn2);,',...
'dn=str2num(strdn);,',...
'dd=abs(sin(dn)-hermite(dn,n1,n2));,',...
'msgbox([''誤差為:'',num2str(dd)],''計算結果'')']);
e1=uicontrol('parent',h0,...
'units','points',...
'tag','e1',...
'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','誤差點:',...
'fontsize',12,...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[160 100 40 20]);
e2=uicontrol('parent',h0,...
'units','points',...
'tag','e2',...
'style','edit',...
'fontsize',12,...
'string','1.00',...
'horizontalalignment','right',...
'backgroundcolor',[1 1 1],...
'position',[20 85 40 20]);
t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','第一節點:',...
'fontsize',12,...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[15 105 50 20]);
e3=uicontrol('parent',h0,...
'units','points',...
'tag','e3',...
'style','edit',...
'fontsize',12,...
'string','3.00',...
'horizontalalignment','right',...
'backgroundcolor',[1 1 1],...
'position',[100 85 40 20]);
t3=uicontrol('parent',h0,...
'units','points',...
'tag','t3',...
'style','text',...
'string','第二節點:',...
'fontsize',12,...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[95 105 50 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');
實例89:mewton形式的hermite插值
h0=figure('toolbar','none',...
'position',[200 50 350 450],...
'name','實例89');
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','N-Hermite插值',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[20 60 70 20],...
'callback',[...
'strn1=get(e2,''string'');,',...
'n1=str2num(strn1);,',...
'strn2=get(e3,''string'');,',...
'n2=str2num(strn2);,',...
'x=0:0.2:2*pi;,',...
'i=1;,',...
'for t=0:0.2:2*pi,',...
'y(i)=sin(t);,',...
'ynh(i)=nhermite(t,n1,n2);,',...
'i=i+1;,',...
'end,',...
'plot(x,y,''b*'',x,ynh,''r-''),',...
'axis([0 7 -1.5 1.5]),',...
'legend(''sin(x)'',''N-Hermite插值'')']);
b2=uicontrol('parent',h0,...
'units','points',...
'tag','b2',...
'style','pushbutton',...
'string','誤差比較',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[170 60 70 20],...
'callback',[...
'strdn1=get(e2,''string'');,',...
'n1=str2num(strdn1);,',...
'strdn2=get(e3,''string'');,',...
'n2=str2num(strdn2);,',...
'strdn=get(e1,''string'');,',...
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -