MATLAB 第五次上机实验报告
- 格式:doc
- 大小:165.50 KB
- 文档页数:5
MATLAB 第五次上机实验报告
Quit 3.3
1题
%calculate x versus y1 and y2
x=0:pi/10:2*pi;
y1=sin(x);
y2=cos(2*x);
%plot y1 and y2;
plot(x,y1,'-ro','LineWidth',2,'MarkerSize',6,'MarkerEdgeColor','b','MarkerFaceColor','b')
hold on
plot(x,y2,'-ro','LineWidth',2,'MarkerSize',6,'MarkerEdgeColor','b','MarkerFaceColor','b')
hold off
legend('sinx','cosx')
2题
Write the MATLAB text string that will produce the following expressions
3题f(x) = sinθ cos2ф
Answer: \it {f}(x)=sin\theta cos2\phi
4题4. Plot of Σx^2 versus x
Answer: plot of \Sigmax^2 versus x
Write the expression produced by the following text sting:
5题
‘\tau\it_{m}’
Answer:
6题
'\bf\itx_{1}^{ 2} + x_{2}^{ 2} \rm(units:\bfm^{2}\rm)'
Answer:
7题how do you display the backslash(\)character in a text string?
Answer : \\
3.8题
% theta -- Angle from microphone axis (radians)
% g -- A function of angle
%Calculat g versus angle
theta=-pi/2:pi/20:pi/2;
g=abs(sinc(4*theta));
%plot g
polar(theta,g,'b-');
title('\bfAntenna Gain vs \theta')
3.11题
%define variables:
% amp --Amplitude response
% c --Capacitance(farads)
% f --frequency of input signal (Hz)
% phase --phase response
% r --resistance(ohms)
% res --v0/ui
%Initialize r & c
r=16000; %16 k ohms
c=1e-6; %1 uf
f=1:2:1000;
%calculate response
res=(j*2*pi*f*r*c)./(1+j*2*pi*f*r*c);
amp=abs(res);
phase=angle(res);
%create plots
subplot(2,1,1);
% Create plots
subplot(2,1,1);
loglog( f, amp );
title('Amplitude Response');
xlabel('Frequency (Hz)');
ylabel('Output/Input Ratio');
grid on;
subplot(2,1,2);
semilogx( f, phase );
title('Phase Response');
xlabel('Frequency (Hz)');
ylabel('Output-Input Phase (rad)');
grid on;
3.12题
%define variables:
% r --the distance of a point from the origin
%theta --the angle of one point in radians with respect to the origin
% k --constant
% calculate response
k=0.5;
theta=0:pi/20:6*pi;
r=k*theta;
%plot r
polar(theta,r)
title('\bfThe Spiral of Archimedes')
6.10题
%Define variables:
%y --equal to e^(i*theta)
%theta --angle varies from 0 to 2*pi
theta=0:pi/20:2*pi;
y=cos(theta) +i* sin(theta);
subplot(2,1,1)
plot(theta,y);
title('\bfTwo-Dimensional Line Plot');
xlabel('\bf\theta');
ylabel('\bfy');
subplot(2,1,2)
plot3(theta,cos(theta),sin(theta));
title('\bfThree-Dimensional Line Plot');
xlabel('\bf\theta');
ylabel('\bfcos\theta');
zlabel('\bfsin\theta');
6.11题
% Define variables :
% e --The natural logtrithm.
% z --the expression of e^(x+i*y)
% Calculate e^(x+i*y) versus x and y% Define variables :
subplot(3,1,1);
[x y]=meshgrid(-1:0.1:1,-2*pi:0.2*pi:2*pi);
z=exp(x+y);
% mesh plot
subplot(3,1,1);
mesh(x,y,real(z));
title('\bfMesh plot');
xlabel('\bfx');
ylabel('\bfy');
zlabel('\bfz');
% surface plot
subplot(3,1,2);
surf(x,y,real(z));
title('\bfSurface plot');
xlabel('\bfx');
ylabel('\bfy');
zlabel('\bfz');
% contour plot
subplot(3,1,3);
contour(x,y,real(z));
title('\bfContour plot');
xlabel('\bfx');
ylabel('\bfy');
zlabel('\bfz');
6.18题
x=0:0.1:2;
y=exp(-x).*sin(x);
subplot(2,2,1)
stem(x,y);
title('\bfStem plot');
xlabel('x');
ylabel('y');
subplot(2,2,2)
stairs(x,y);
title('\bfstair plot');
xlabel('x');
ylabel('y');
subplot(2,2,3)
bar(x,y);
title('\bfBar plot');
xlabel('x');
ylabel('y');
subplot(2,2,4)
compass(x,y);
title('\bcompass plot');
xlabel('x');
ylabel('y');
6.19题
money=[5 10 7 5 15];
explode=[0 1 0 0 0];
pie(money,explode);
title('\bfthepie chart of their contributions ');
legend('George','Sam','Betty','Charlie','Suzie')