矩阵实验室实验
r=5*cos(t)+4; 第三章 第五章
5.2(1) 3.5(1) 4.3
n=100; subplot(1,2,1) x1=0:pi/12:pi/2; i=1:1:n; polar(t,r,'.') y1=[0,0.2588,0.5000y=sum(1./(i.^2)); subplot(1,2,2) ,0.7071,0.8660,0.96Y t1=-pi/3:pi/250:pi/3; 59,1.000];
r1=5*(sin(t1).^2)./cosp1=polyfit(x1,y1,5) 第二种
y=0; (t1); t1i=0:pi/12:pi/2; n=100; polar(t1,r1,'r') y1i=polyval(p1,t1i)
for i=1:1:n 4.4(1)
y=y+1/(i^2); t=0:0.1*pi:2*pi; x=0:pi/12:pi/2; end x=exp(-t/20).*cos(t); y=sin(x); y y=exp(-t/20).*sin(t); interp1(x,y,x,'line
z=t; ar') 3.5(2)
y=1; plot3(x,y,z) 5.3 n=100; N=64;
fori=1:100 T=5; 4.4(2)
y=y*(2*i)*(2*i)/((2*i-z=5*ones(size(x)); t=linspace(0,T,N); 1)*(2*i+1)); x=-5:5; h=exp(-t); end y=-5:5; dt=t(2)-t(1); y [x,y]=meshgrid(x,y); f=1/dt;
mesh(x,y,z) H=fft(h); 第四章
4.1 shading interp F=H(1:N/2+1); y=x-x.^3/6; f=f*(0:N/2)/N; subplot(1,2,1) 4.5 plot(f,abs(F),'-*') plot(x,y) maxx=200; xlabel('Frequency')subplot(1,2,2) m=moviein(maxx); ;
ezplot('x^2+2*y^2-64') [x,y,z]=sphere(40); ylabel('|F(k)|')
for r=1:maxx 5.4 4.2
t=-pi:0.1*pi:pi; X=x*r; P=[2,-3,0,5,13]; y=1./(1+exp(-t)); Y=y*r; Q=[1,5,8]; subplot(2,2,1);bar(t,y Z=z*r; p1=polyder(P) ,'b'); mesh(X,Y,Z); p2=polyder(P,Q)
axis([-maxx,maxx,-maxx[p,q]=polyder(P,Q) title('条形图');
subplot(2,2,2);stairs(,maxx,-maxx,maxx]) 5.5
axis square; t,y,'r'); P1=[1,2,4,0,5];
m(:,r)=getframe; P2=[0,0,0,1,2]; title('阶梯图');
subplot(2,2,3);stem(t,end P3=[0,0,1,2,3]; y,'y'); movie(m,2) P=P1+P2+P3
5.2(2) x=roots(P) title('杆图');
subplot(2,2,4);semilogx=1:1:100; x=[-1,1.2,-1.4;0.75y(t,y,'g'); y=sqrt(x); ,2,3.5;0,5,2.5];
interp1(x,y,x,'cubiy1=polyval(P,x) title('对数图');
t=0:pi/10:2*pi; c') y2=polyvalm(P,x)
8.5 syms x y n; 第八章
syms x n; [x 8.2(2)
sym x; s=symsum(x^(2*n-1)/(2*y]=dsolve('x*D2y+(1-n)
limit((sqrt(pi)-sqrt(an-1),'x',inf) *Dy+y=0','y=(0)=0','Dy
cos(x)))/sqrt(x+1),x,- (0)=0','x') 1,'right') 8.8
第十章
计算器(编程)
hf=figure('Color',[1,0,1],'Name','计算器','Menubar','none'); uicontrol(hf,'Style','Text','Units','normalized',...
'Position',[0.05,0.8,0.45,0.1],'String','输入框',...
'Horizontal','center','Back',[1,0.1,0.6]); uicontrol(hf,'Style','Text','Units','normalized',...
'Position',[0.5,0.8,0.45,0.1],'String','输出框',...
'Horizontal','center');
h1=uicontrol(hf,'Style','Edit','Units','normalized',...
'Position',[0.05,0.6,0.25,0.1],...
'Horizontal','center','Back',[1,0.2,0.1]); h2=uicontrol(hf,'Style','Edit','Units','normalized',...
'Position',[0.05,0.4,0.25,0.1],...
'Horizontal','center','Back',[1,0.2,0.1]); h3=uicontrol(hf,'Style','Text','Units','normalized',...
'Position',[0.5,0.4,0.25,0.25],...
'Horizontal','center','Back',[1,0.2,0.1]); COMM1=['a=str2num(get(h1,''String''));',...
'b=str2num(get(h2,''String''));',...
's=a+b;','set(h3,''String'',s);'];
COMM2=['a=str2num(get(h1,''String''));',...
'b=str2num(get(h2,''String''));',...
's=a-b;','set(h3,''String'',s);'];
COMM3=['a=str2num(get(h1,''String''));',...
'b=str2num(get(h2,''String''));',...
's=a*b;','set(h3,''String'',s);'];
COMM4=['a=str2num(get(h1,''String''));',...
'b=str2num(get(h2,''String''));',...
's=a/b;','set(h3,''String'',s);'];
uicontrol(hf,'Style','Push','Units','normalized',...
'Position',[0.10,0.1,0.1,0.12],...
'String','+','Back',[1,0.2,0.1],...
'Call',COMM1);
uicontrol(hf,'Style','Push','Units','normalized',...
'Position',[0.20,0.1,0.1,0.12],...
'String','-','Back',[1,0.2,0.1],...
'Call',COMM2);
uicontrol(hf,'Style','Push','Units','normalized',...
'Position',[0.30,0.1,0.1,0.12],...
'String','*','Back',[1,0.2,0.1],...
'Call',COMM3);
uicontrol(hf,'Style','Push','Units','normalized',...
'Position',[0.40,0.1,0.1,0.12],...
'String','/','Back',[1,0.2,0.1],...
'Call',COMM4);
计算器(图形界面)
function pushbutton1_Callback(hObject, eventdata, handles) a=str2num(get(handles.edit1,'string'));
b=str2num(get(handles.edit4,'string'));
s=a+b;
set(handles.edit2,'string',s);
10.1
screen=get(0,'ScreenSize');
figure('color',[1,1,1],'MenuBar','none')
hm=uimenu(gcf,'Label','File');
hm1=uimenu(hm,'Label','New');
uimenu(hm1,'Label','New Item');
hm2=uimenu(hm,'Label','Open');
uimenu(hm2,'Label','Open Item');
hm3=uimenu(hm,'Label','Save','Enable','off'); uimenu(hm3,'Label','Save Item');
hm4=uimenu(hm,'Label','Exit','Call','close(gcf)'); hn=uimenu(gcf,'Label','help');
hn1=uimenu(hn,'Label','About...');
uimenu(hn1,'Label','Help Item','Call',...
'set(hm3,''Enable'',''on'')');
10.2 10.3 x=0:1:10; hpopup=uicontrol(gcf,'Style','popup'
y=x.*x; ,'String',... h1=plot(x,y); hc=uicontextmenu; 'cos|sum|fix|exp|roots','CallBack',.
.. h1c=uimenu(hc,'Label','颜色');
uimenu(h1c,'Label','Red','Call',...
'set(h1,''Color'',''r'')'); ['cbcol=[''C'',''S'',''F'',''E'',''R
uimenu(h1c,'Label','Blue','Call',... ''];',...
'set(h1,''color'',''b'')'); uimenu(h1c,'Label','Yellow','Call',.'set(gcf,''Function'',cbcol(get(hpop
.. up,''Value'')))']);
'set(h1,''color'',''y'')'); hedit=uicontrol(gcf,'Style','edit',.
set(h1,'UIContextMenu',hc); ..
'Call','comm(hedit)'); 'Unit','normalized','String','输
hpush2=uicontrol(gcf,'Style','push',入多项式系数',...
'Unit','normalized',... 'Position' ,[0.6,0.2,0.2,0.6],'Max',
10); 'Position',[0.45,0.45,0.1,0.1],'Callhpush1=uicontrol(gcf,'Style','push',Back',...
'Unit','normalized',...
'set(hpush2,''Position'',[rand,rand,
'Position',[0.8,0.3,0.15,0.15],'Stri0.1,0.1])');
ng','求根',...
10.4 '));
set(handles.text1,'FontSize',n1) 设置字体
function checkbox2_Callback(hObject, 10.5
eventdata, handles) 绘图按钮函数设置
function pushbutton1_Callback(hObject,
set(handles.text1,'FontAngle','normaeventdata, handles) l') com1=get(handles.edit1,'String');
if get(handles.checkbox2,'Value')==1 com2=get(handles.edit2,'String');
com3=get(handles.edit3,'String'); set(handles.text1,'FontAngle','italia=eval(com1);
c') b=eval(com2);
end n=eval(com3);
t=-2*pi:0.1*pi:2*pi; 设置颜色
function r=a*cos(b+n*t);
radiobutton1_Callback(hObject, polar(t,r)
eventdata, handles)
set(handles.text1,'ForegroundColor',
'Red')
设置大小
function pushbutton1_Callback(hObject, eventdata, handles)
n1=str2num(get(handles.edit1,'String