搜档网
当前位置:搜档网 › matlab实习部分答案

matlab实习部分答案

实习一

(12+2*(7-4))/3^2


t=0:pi/50:4*pi;
y0=exp(-t/3);
y=exp(-t/3).*sin(3*t);
plot(t,y,'-r',t,y0,':b',t,-y0,':b')
实习二

Time=[11 12 1 2 3 4 5 6 7 8 9 10]

X_Data=[2.32 3.43 4.37 5.98]

x=[1 2 3 4];y=[1 0 5];[X,Y]=meshgrid(x,y)

sym_matrix=sym ('[a b c;Jack Help_Me NO_WAY]')

syms a b c;
M1=sym ('Classical');
M2=sym ('Jazz');
M3=sym ('Blues');
A=[a b c;M1,M2,M3;sym([2 3 5])]

g=[1 2 3 4];h=[4 3 2 1];
s1=g+h,s2=g.*h,s3=g.^h,s4=g.^2,s5=2.^h

A=[2 0 -1 ;1 3 2];B=[1 7 -1;4 2 3;2 0 1];
M=A*B
det_B=det(B)
rank_A=rank(A)
inv_B=inv(B)
[V,D]=eig(B)
X=A/B
Y=B\A

x=[-4.85 -2.3 -0.2 1.3 4.56 6.75]
ceil_X=ceil(X)
fix_x=fix(x)
floor_x=floor(x)
round_x=round(x)

x=[2 3 pi/2 9]
y=[2,3,pi/2,9]

A=[0:2*pi/49:pi*2];
A=linspace(0,2*pi,50);
B=A(1:5)
C=A(7:end)
A(find(A>2))
A([3 5 9])=100

A=[1 2 3;4 5 6]
A(2,1)
A(2)

A=[1 2 3;4 5 6];B=[1 2 3;6 7 8];
m=A.*B
n=A*B

rand('state',0);
A=rand(3,5);
[ii,jj]=find(A>0.5);
disp('ii jj')
disp([ii jj])


(12)写出生成如图所示的波形

t=0:0.01:10;
y=1-exp(-0.5*t).*cos(2*t);
plot(t,y,'r')

x=0:0.01:10;
y=sin(x);plot(x,y,'b:');hold on;
y(find(y<0))=0;y(find(y>sqrt(3)/2))=sqrt(3)/2;
plot(x,y,'b')

a='This is an example.'
a14=a(1:4)
Name='thomas r.lee';name1=double(Name)
name1=102;name2=char(name1)
b='example''3.1.2-1'''
Name=['Thomas R.Lee ';'Senior Developer'];
Name=char('Thomas R.Lee','Senior Developer','Kaiyi.wang','threemam','abcd


clear
a=2;
w=3;
t=0:0.01:10;
y=exp(-a*t).*sin(w*t);
[y_max,i_max]=max(y);
t_text=['t=',num2str(t(i_max))];
y_text=['y=',num2str(y_max)];
max_text=char('maximum',t-text,y_text);
tit=['y=exp(-',num2str(a),'t)*sin(',num2str(w),'t)'];
plot(t,zeros(size(t)),'k')
hold on
plot(t,y,'b')
plot(t(i_max),y_max,'r.','MarkerSize',20)
text(t(i_max)+0.3,y_max+.05,max_text)
title(tit),xlabel('t'),ylabel('y'),hold off


实习三

x=-2*pi:pi/10:2*pi;
x=x+(x==0)*eps;y=sin(x)./x;
plot(x,y)

x=x+(x==0)*eps;
y=sin(x)./x; %(准备数据,处理分母零点))
plot(x,y) %(用plot作图):


t=(0:pi/100:pi);
y1=sin(t);y=-sin(t);
y2=sin(t).*sin(9*t);t3=pi*(0:9)/9;
y3=sin(t3).*sin(9*t3);
plot(t,y1,'r:',t,y,'r:',t,y2,'b',t3,y3,'bo'),axis([0,pi,-1,1])
gtext('该点数值x')


ezplot('sin(x)/x',[-4*pi,4*pi])

fplot('sin(x)/x',[-2*pi,2*pi])

t=-2*pi:0.01:2*pi;
x=2*cos(t);y=2*sin(t);z=3*t;
plot3(x,y,z,'r:')

x=-1:0.05:1;y=x;
[x,y]=meshgrid(x,y);
z=x.^2+2*y.^2;
mesh(x,y,z)


x=-1:0.05:1;y=x;
[x,y]=meshgrid(x,y);
z=x.^2+2*y.^2;
surf(x,y,z)



sphere(50)

cylinder(5,30)





X=1:10;
Y=[1 2 3 4 5 6 7 8];
Z=1:-1:-10;
plot(X)
plot(Y)
plot(X,Z)


t1=(0:11)/11*pi;
y1=sin(t1).*sin(9*t1);
t2=(0:100)/100*pi;
y2=sin(t2).*sin(9*t2);
subplot(2,2,1),plot(t1,y1,'r.'),axis([0,pi,-1,1]),title('子图(1)')
subplot(2,2,2),plot(t2,y2,'r.'),axis([0,pi,-1,1]),title('子图(2)')
subplot(2,2,3),plot(t1,y1,t1,y1,'r.'),axis([0,pi,-1,1]),title('子图

(3)')
subplot(2,2,4),plot(t2,y2),axis([0,pi,-1,1]),title('子图(4)')
ginput %用鼠标选择四个峰值,然后回车


clf;t=6*pi*(0:100)/100;y=1-exp(-0.3*t).*cos(0.7*t);
tt=t(find(abs(y-1)>0.05));ts=max(tt);
plot(t,y,'r-','linewidth',3)
axis([-inf,6*pi,0.6,inf])
set(gca,'xtick',[2*pi,4*pi,6*pi],'ytick',[0.95,1,1.05,max(y)])
grid on
title('\ity=1-e^{-\alphat}cos{\omegat}')
text(13.5,1.2,'\fontsize{12}{\alpha}=0.3')
text(13.5,1.1,'\fontsize{12}{\omega}=0.7')
hold on;plot(ts,0.95,'bo','markersize',10);hold off
cell_string{1}='\fontsize{12}\uparrow';
cell_string{2}='\fontsize{16}\fontname{隶书}镇定时间';
cell_string{3}='\fontsize{6}';
cell_string{4}=['\fontsize{14}\rmt_{s}=' num2str(ts)];
text(ts,0.85,cell_string)
xlabel('\fontsize{14}\bft\rightarrow')
ylabel('\fontsize{14}\bfy\rightarrow')

x=linspace(-10*pi,10*pi,1000);
d=sin(x);
e=x;
y=d./e;
plot(x,y);

t=linspace(0,2*pi,1000);
d=exp(-0.5*t);
m=cos(t);
y=d.*m;
plot(t,y);
set(gca,'xtick',[0.5,1.2,4.5],'ytick',[0.2,1,1.05,3.5])
value=0.6;
pos=find(y-value>=0);
tt=t(pos);t2=max(tt);
hold on;
plot(t2,y2,'or','MarkerSize',5);
cell_string=['\fontsize{14}\rmts=' num2str(t2)];
text(t2+0.05,0.6,['\fontsize{14}\rmts=' num2str(t2)])


实习五

X=linspace(-pi,pi,25);
Y=sin(X);
plot(X,Y,'rX');
gcf
gca

h_line = findobj(gca,'Marker','X')
get(h_line)
h_line_parent = get(h_line,'Parent');
isequal(h_line_parent,gca)
set(gca,'Color',[0,0,0])
set(h_line,'Color',[1 1 1],'MarkerSize',10);
set(gca,'XGrid','on','GridLineStyle','-.','XColor',[0.75 0.75 0])
set(gca,'YGrid','on','GridLineStyle','-.','YColor',[0 0.75 0.75])
set(gcf,'Color',[0 0 1])

t=(0:pi/50:2*pi)';
k=0.4:0.1:1;Y=cos(t)*k;
line(t,Y,'Color',[1 0 0],'LineStyle','-.')
clf reset
set(gca,'ColorOrder',[0 0 0;0.7 0.7 0.7],'LineStyle','-|:')
line(t,Y)
clf reset
set(gcf,'DefaultAxesLineStyleOrder','-|:');
set(gcf,'DefaultAxesColorOrder',[1 0 0;0 0 1]);
line(t,Y)

h_fig=figure
Set(h_fig,'menubar','none')
Set(gcf,'menubar','figure')

figure
h_menu=uimenu(gcf,'label','&Color');
h_submenu1=uimenu(h_menu,'label','&Blue','callback','set(gcf,''color'',''blue'')');
h_submenu2=uimenu(h_menu,'label','&Red','callback','set(gcf,''color'',''red'')','Accelerator','r');


t=(-3*pi:pi/50:3*pi)+eps;
y=sin(t)./t;
hline=plot(t,y);
cm=uicontextmenu;
uimenu(cm,'label','Red','callback','set(hline,''color'',''r''),')
uimenu(cm,'label','Blue','callback','set(hline,''color'',''b''),')
uimenu(cm,'label','Green','callback','set(hline,''color'',''g''),')
set(hline,'uicontextmenu',cm)



clf reset
set(gcf,'menubar','none')
set(gcf,'unit','normalized','position',[0.2,0.2,0.64,0.32]);
set(gcf,'defaultuicontrolunits','normalized')
h_axes=axes('position',[0.05,0.2,0.6,0.6]);
t=0:pi/50:2*pi;y=sin(t);plot(t,y);
set(h_axes,'xlim',[0,2*pi]);
set(gcf,'defaultuicontrolhorizontal','left');
htitle=title('正弦曲线');
set(gcf,'defaultuicontrolfontsize',12);
uicontrol('style',

'frame',...
'position',[0.67,0.55,0.25,0.25]);
uicontrol('style','text',...
'string','正斜体图名:',...
'position',[0.68,0.77,0.18,0.1],...
'horizontal','left');
hr1=uicontrol(gcf,'style','radio',...
'string','正体','position',[0.7,0.69,0.15,0.08]);
set(hr1,'value',get(hr1,'Max'));
set(hr1,'callback',[...
'set(hr1,''value'',get(hr1,''Max'')),',...
'set(hr2,''value'',get(hr2,''Min'')),',...
'set(htitle,''fontangle'',''normal''),']);
hr2=uicontrol(gcf,'style','radio',...
'string','斜体','position',[0.7,0.58,0.15,0.08],...
'callback',[...
'set(hr1,''value'',get(hr1,''Min'')),',...
'set(hr2,''value'',get(hr2,''Max'')),',...
'set(htitle,''fontangle'',''italic''),']);
ht=uicontrol(gcf,'style','toggle',...
'string','Grid',...
'position',[0.67,0.40,0.15,0.12],...
'callback','grid');


figure;
x=-2*pi:pi/40:2*pi;
y=cos(x);
hl_cos=plot(x,y)
set(hl_cos,'Color',[0.2 0.8 0.8],'linewidth',3);
h_menu=uimenu(gcf,'label','&line');
h_submenu1=uimenu(h_menu,'label','&line style','callback','set(hl_cos,''LineStyle'','':'')');
h_submenu2=uimenu(h_menu,'label','&line color','callback','set(hl_cos,''color'',''red'')');
h_submenu3=uimenu(h_menu,'label','&line width','callback','set(hl_cos,''linewidth'',12)');


clf reset
H=axes('unit','normalized','position',[0,0,1,1],'visible','off');
set(gcf,'currentaxes',H);
str='\fontname{隶书}二阶系统的单位阶跃响应曲线';
text(0.12,0.93,str,'fontsize',13);
h_fig=get(H,'parent');
set(h_fig,'unit','normalized','position',[0.1,0.2,0.7,0.4]);
h_axes=axes('parent',h_fig,...
'unit','normalized','position',[0.1,0.15,0.55,0.7],...
'xlim',[0 15],'ylim',[0 1.8],'fontsize',8);
h_text=uicontrol(h_fig,'style','text',...
'unit','normalized','position',[0.67,0.73,0.25,0.14],...
'horizontal','left','string',{'输入阻尼比系数','zeta ='});
h_edit=uicontrol(h_fig,'style','edit',...
'unit','normalized','position',[0.67,0.59,0.25,0.14],...
'horizontal','left',...
'callback',['z=str2num(get(gcbo,''string''));',...
't=0:0.1:15;',...
'y=step(1,[1 2*z(k) 1],t);',...
'plot(t,y);',...
'if (length(z)>1) ,hold on,end,',...
'hold off,']);
h_push1=uicontrol(h_fig,'style','push',...
'unit','normalized','position',[0.67,0.37,0.12,0.15],...
'string','grid on','callback','grid on');
h_push2=uicontrol(h_fig,'style','push',...
'unit','normalized','position',[0.67,0.15,0.12,0.15],...
'string','grid off','callback','grid off');

相关主题