matlab参考资料
- 格式:pdf
- 大小:491.62 KB
- 文档页数:14
1-3.(1)Abc, wu_2004,是合法的;2004x, li1-1, a&b, qst.u, _ xyz是不合法的。
1-4.(1)[12+2*(7-4)]/3^2
ans = 2
(2)>> A=[1,2,3;4,5,6;7,8,9]
A =
1 2 3
4 5 6 7 8 9
(3) >> clear;x=-8:0.5:8;
y=x';
X=ones(size(y))*x;
Y=y*ones(size(x)); R=sqrt(X.^2+Y.^2)+eps;
Z=sin(R)./R;
mesh(X,Y,Z);
colormap(hot)
xlabel('x'),ylabel('y'),zlabel('z') >>
1-11
2-1.
2-2. >> x1=0:pi/25:2*pi
x1 =
Columns 1 through 8
0 0.1257 0.2513 0.3770 0.5027 0.6283 0.7540 0.8796
Columns 9 through 16
1.0053 1.1310 1.2566 1.3823 1.5080 1.6336 1.7593 1.8850
Columns 17 through 24
2.0106 2.1363 2.2619 2.3876 2.5133 2.6389 2.7646 2.8903
Columns 25 through 32
3.0159 3.1416 3.2673 3.3929 3.5186 3.6442 3.7699 3.8956
Columns 33 through 40
4.0212 4.1469 4.2726 4.3982 4.5239 4.6496 4.7752 4.9009
Columns 41 through 48
5.0265 5.1522 5.2779 5.4035 5.5292 5.6549 5.7805 5.9062
Columns 49 through 51
6.0319 6.1575 6.2832
>> x2=linspace(0,2*pi,50)
x2 =
Columns 1 through 8
0 0.1282 0.2565 0.3847 0.5129 0.6411 0.7694 0.8976
Columns 9 through 16
1.0258 1.1541 1.2823 1.4105 1.5387 1.6670 1.7952 1.9234
Columns 17 through 24
2.0517 2.1799 2.3081 2.4363 2.5646 2.6928 2.8210 2.9493
Columns 25 through 32
3.0775 3.2057 3.3339 3.4622 3.5904 3.7186 3.8468 3.9751
Columns 33 through 40
4.1033 4.2315 4.3598 4.4880 4.6162 4.7444 4.8727 5.0009
Columns 41 through 48
5.1291 5.2574 5.3856 5.5138 5.6420 5.7703 5.8985 6.0267
Columns 49 through 50
6.1550 6.2832
2-3. t=0:pi/5:2*pi;
y=exp(-2*t).*sin(t)
y =
Columns 1 through 8
0 0.1673 0.0770 0.0219 0.0039 0.0000 -0.0003 -0.0001
Columns 9 through 11
-0.0000 -0.0000 -0.0000
2-4. A=[1,2;3,4];B=[5,6;7,8]; X=A*B
Y=A.*B
X =
19 22
43 50
Y =
5 12
21 32
2-5. A=[1 2 3 4;1 3 5 0];B=[1 0 5 3;1 5 0 5];
C=A&B D=A|B
E=~A
F=(A==B)
G=(A>B)
C =
1 0 1 1
1 1 0 0
D =
1 1 1 1 1 1 1 1
E =
0 0 0 0
0 0 0 1
F =
1 0 0 0
1 0 0 0
G =
0 1 0 1
0 0 1 0
2-7. A=[1 2 3 4;1 3 5 0]; B=num2str(A)
size(A)
size(B)
B =
1 2 3 4
1 3 5 0
ans =
2 4
ans =
2 10
3-1. t=0:0.02:18;
xi1=0.2; beta1=sqrt(1-xi1^2); sita1=atan(beta1/xi1);
y1=1-exp(-xi1*t).*sin(beta1*t+sita1)*(1/beta1);
plot(t,y1,'b'),hold on xi2=0.4;
beta2=sqrt(1-xi2^2);
sita2=atan(beta2/xi2);
y2=1-exp(-xi2*t).*sin(beta2*t+sita2)*(1/beta2);
plot(t,y2,'b'),hold on xi3=0.6;beta3=sqrt(1-xi3^2);sita3=atan(beta3/xi3);
y3=1-exp(-xi3*t).*sin(beta3*t+sita3)*(1/beta3);
plot(t,y3,'r'),hold on
xi4=0.8;beta4=sqrt(1-xi4^2);sita4=atan(beta4/xi4);
y4=1-exp(-xi4*t).*sin(beta4*t+sita4)*(1/beta4); plot(t,y4,'c'),hold on
xlabel('t/s'),ylabel('y')
text(3.5,0.9,'{\xi}=0.8'),text(5.4,1.5,'{\xi}=0.2')
3-2. x=-4:4;y=x;
[X,Y]=meshgrid(x,y); Z=1./(sqrt((1-X).^2+Y.^2)+sqrt((1+X).^2+Y.^2));
subplot(1,3,1),surf(X,Y,Z);
subplot(1,3,2),mesh(X,Y,Z);
subplot(1,3,3),plot3(x,y,1./(sqrt((1-x).^2+y.^2)+sqrt((1+x).^2+y.^2)));box on
3-3. t=(0:0.02/pi:30*pi);
x=sin(t);y=cos(t);z=t;
plot3(x,y,z,'g') box on
习题4
1. 请分别用for和while循环语句计算
63
02
iiK的程序,再写出一种避免循环的计算程序(提示:可考虑利
用MATLAB中的sum(X,n)函数,实现沿数组X的第n维求和)
答:for语句程序及输出结果:
clear;k(1)=1;
for i=0:62
k(i+2)=k(i+1)+2^(i+1);
i=i+1;
end;
i,k(i+1)
>> i =
63
ans =
1.8447e+019
while语句程序及输出结果:
clear;k(1)=1;i=0
while i<=62
k(i+2)=k(i+1)+2^(i+1);
i=i+1;
end;
i,k(i+1)
i =
63
ans =
1.8447e+019
避免循环的计算程序及输出结果:
clear;i=(0:63);
m=linspace(1,1,64);
k=m.*pow2(i);
sum(k,2)
ans =
1.8447e+019
习题5
1将下列系统的传递函数模型用matlab语言表达出来。
(1) G1(s)=(s4+35s3+291s2+1093s+1700)/(s5+289s4+254s3+2541s2+4684s+1700);
(2) G2(s)=15(s+3)/(s+1)(s+5)(s+15);
(3) G3(s)=100s(s+2)2(s2+3s+2)/(s+1)(s-1)(s3+2s2+5s+2); 答:(1) >> sys1=tf([1,35,291,1093,1700],[1,289,254,2541,4684,1700])
Transfer function:
s^4 + 35 s^3 + 291 s^2 + 1093 s + 1700
-------------------------------------------------------------------------- s^5 + 289 s^4 + 254 s^3 + 2541 s^2 + 4684 s + 1700
(2) >> sys2=zpk(-3,[-1,-5,-15],15)
Zero/pole/gain:
15 (s+3) ------------------
(s+1) (s+5) (s+15)
(3) >> sys1=tf([1,3,2],[1,2,5,2]);
>> sys2=zpk([0,-2,-2],[1,-1],100);
>> sys3=sys1*sys2 Zero/pole/gain:
100 s (s+2)^3 (s+1)
----------------------------------------------
(s+1) (s+0.4668) (s-1) (s^2 + 1.533s + 4.284)
>> sys4=minreal(sys3)
Zero/pole/gain:
100 s (s+2)^3
----------------------------------------
(s-1) (s+0.4668) (s^2 + 1.533s + 4.284)