MATLAB编程练习(含答案很好的).pdf
《MATLAB编程练习(含答案很好的).pdf》由会员分享,可在线阅读,更多相关《MATLAB编程练习(含答案很好的).pdf(37页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、1 001 双峰曲线图:z=peaks(40);mesh(z);surf(z)002 解方程:A=3,4,-2;6,2,-3;45,5,4;B=14;4;23;root=inv(A)*B 003 傅里叶变换load mtlb;subplot(2,1,1);plot(mtlb);title(原始语音信息);y=fft(mtlb);subplot(2,1,2);yy=abs(y);plot(yy);title(傅里叶变换)004 输入函数:a=input(How many applesn,s)005 输出函数a=1 2 3 4;5 6 7 8;12 23 34 45;34 435 23 34 a=
2、1 2 3 4 5 6 7 8 12 23 34 45 34 435 23 34 disp(a)a=1 2 3 4 5 6 7 8 12 23 34 45 34 435 23 34 b=input(how many peoplen,s)2 how many people two people b=two people disp(b)two people 006 求一元二次方程的根a=1;b=2;c=3;d=sqrt(b2-4*a*c);x1=(-b+d)/(2*a)x1=-1.0000+1.4142i x2=(-b-d)/(2*a)x2=-1.0000-1.4142i 007 求矩阵的相乘、转
3、置、存盘、读入数据A=1 3 5;2 4 6;-1 0-2;-3 0 0;B=-1 3;-2 2;2 1;C=A*B C=3 14 2 20-3-5 3-9 C=C C=3 3 2-3 3 14 20-5-9 save mydat C clear load mydat C 008 编写数学计算公式:A=2.1;B=-4.5;C=6;D=3.5;E=-5;K=atan(2*pi*A)+E/(2*pi*B*C)/D)K=1.3121 009 A=1 0-1;2 4 1;-2 0 5;B=0-1 0;2 1 3;1 1 2;H=2*A+B H=2-1-2 6 9 5-3 1 12 M=A2-3*B
4、M=3 3-6 2 13-2-15-3 21 Y=A*B Y=-1-2-2 9 3 14 5 7 10 4 R=B*A R=-2-4-1-2 4 14-1 4 10 E=A.*B E=0 0 0 4 4 3-2 0 10 W=AB W=0.3333-1.3333 0.6667 0.2500 1.0000 0.2500 0.3333-0.3333 0.6667 P=A/B P=-2.0000 3.0000-5.0000-5.0000 3.0000-4.0000 7.0000-9.0000 16.0000 Z=A.B Warning:Divide by zero.Z=0-Inf 0 1.0000
5、0.2500 3.0000-0.5000 Inf 0.4000 D=A./B Warning:Divide by zero.5 D=Inf 0-Inf 1.0000 4.0000 0.3333-2.0000 0 2.5000 010 a=4.96;b=8.11;M=exp(a+b)/log10(a+b)M=4.2507e+005 011 求三角形面积:a=9.6;b=13.7;c=19.4;s=(a+b+c)/2;area=sqrt(s*(s-a)*(s-b)*(s-c)area=61.1739 012 逻辑运算A=-1 0-6 8;-9 4 0 12.3;0 0-5.1-2;0-23 0-7
6、;B=A(:,1:2)B=-1 0-9 4 0 0 0-23 C=A(1:2,:)C=-1.0000 0-6.0000 8.0000-9.0000 4.0000 0 12.3000 6 D=B D=-1-9 0 0 0 4 0-23 A*B ans=1.0000-184.0000-27.0000-266.9000 0 46.0000 207.0000 69.0000 C C&D ans=1 0 0 0 0 1 0 1 C|D ans=1 1 1 1 1 1 0 1 C|D ans=0 1 1 1 1 0 1 0 7 013 矩阵运算练习:A=8 9 5;36-7 11;21-8 5 A=8 9
7、 5 36-7 11 21-8 5 B B=-1 3-2 2 0 3-3 1 9 RT=A*B RT=-5 29 56-83 119 6-52 68-21 QW=A.*B QW=-8 27-10 72 0 33-63-8 45 ER=A3 ER=6272 3342 2944 15714-856 5260 8142-1906 2390 BF=A.3 BF=8 512 729 125 46656-343 1331 9261-512 125 A/B ans=3.1341 4.9634-0.4024-1.2561 12.5244-3.2317-1.9878 6.4512-2.0366 EKV=BA E
8、KV=10.7195-1.2683 3.5244 9.4756 1.5854 3.7195 4.8537-1.4878 1.3171 KDK=A,B KDK=8 9 5-1 3-2 36-7 11 2 0 3 21-8 5-3 1 9 ERI=A;B ERI=8 9 5 36-7 11 21-8 5-1 3-2 2 0 3-3 1 9 014 一般函数的调用:A=2 34 88 390 848 939;9 S=sum(A)S=2301 min(A)ans=2 EE=mean(A)EE=383.5000 QQ=std(A)QQ=419.3794 AO=sort(A)AO=2 34 88 390
9、848 939 yr=norm(A)yr=1.3273e+003 RT=prod(A)RT=1.8583e+012 gradient(A)10 ans=32.0000 43.0000 178.0000 380.0000 274.5000 91.0000 max(A)ans=939 median(A)ans=239 diff(A)ans=32 54 302 458 91 length(A)ans=6 sum(A)ans=2301 cov(A)ans=1.7588e+005 015 矩阵变换:11 A=34 44 23;8 34 23;34 55 2 A=34 44 23 8 34 23 34 5
10、5 2 tril(A)ans=34 0 0 8 34 0 34 55 2 triu(A)ans=34 44 23 0 34 23 0 0 2 diag(A)ans=34 34 2 norm(A)ans=94.5106 rank(A)ans=3 12 det(A)ans=-23462 trace(A)ans=70 null(A)ans=Empty matrix:3-by-0 eig(A)ans=80.1587 12.7671-22.9257 poly(A)ans=1.0e+004*0.0001-0.0070-0.1107 2.3462 logm(A)Warning:Principal matri
11、x logarithm is not defined for A with nonpositive real eigenvalues.A non-principal matrix logarithm is returned.In funm at 153 In logm at 27 ans=3.1909+0.1314i 1.2707+0.1437i 0.5011-0.2538i 13 0.4648+0.4974i 3.3955+0.5438i 0.1504-0.9608i 0.2935-1.2769i 0.8069-1.3960i 3.4768+2.4663i fumn(A)?Undefined
12、 command/function fumn.inv(A)ans=0.0510-0.0502-0.0098-0.0326 0.0304 0.0255 0.0305 0.0159-0.0343 cond(A)ans=8.5072 chol(A)?Error using=chol Matrix must be positive definite.lu(A)ans=34.0000 44.0000 23.0000 0.2353 23.6471 17.5882 1.0000 0.4652-29.1816 pinv(A)ans=0.0510-0.0502-0.0098-0.0326 0.0304 0.02
13、55 0.0305 0.0159-0.0343 svd(A)ans=14 94.5106 22.3456 11.1095 expm(A)ans=1.0e+034*2.1897 4.3968 1.9382 1.3154 2.6412 1.1643 1.8782 3.7712 1.6625 sqrtm(A)ans=5.2379+0.2003i 3.4795+0.2190i 1.8946-0.3869i 0.5241+0.7581i 5.1429+0.8288i 2.0575-1.4644i 3.0084-1.9461i 4.7123-2.1276i 2.1454+3.7589i 016 多项式的计
14、算:A=34 44 23;8 34 23;34 55 2 A=34 44 23 8 34 23 34 55 2 P=poly(A)P=1.0e+004*0.0001-0.0070-0.1107 2.3462 15 PPA=poly2str(P,X)PPA=X3-70 X2-1107 X+23462 017 多项式的运算:p=2 6 8 3;w=32 56 0 2;m=conv(p,w)m=64 304 592 548 180 16 6 q,r=deconv(w,p)q=16 r=0-40-128-46 dp=polyder(w)dp=96 112 0 num,den=polyder(w,p)n
15、um=80 512 724 312-16 den=4 24 68 108 100 48 9 16 b=polyfit(p,w,4)Warning:Polynomial is not unique;degree=number of data points.In polyfit at 74 b=-0.6704 9.2037-32.2593 0 98.1333 r=roots(p)r=-1.2119+1.0652i-1.2119-1.0652i-0.5761 018 求多项式的商和余p=conv(1 0 2,conv(1 4,1 1)p=1 5 6 10 8 q=1 0 1 1 q=1 0 1 1
16、w,m=deconv(p,q)w=1 5 m=0 0 5 4 3 cq=w;cr=m;disp(cr,poly2str(m,x)17 5 x2+4 x+3 disp(cq,poly2str(w,x)x+5 019 将分式分解a=1 5 6;b=1;r,p,k=residue(b,a)r=-1.0000 1.0000 p=-3.0000-2.0000 k=020 计算多项式:a=1 2 3;4 5 6;7 8 9;p=3 0 2 3;q=2 3;x=2;r=roots(p)r=0.3911+1.0609i 0.3911-1.0609i-0.7822 p1=conv(p,q)p1=6 9 4 12
17、 9 18 p2=poly(a)p2=1.0000-15.0000-18.0000-0.0000 p3=polyder(p)p3=9 0 2 p4=polyval(p,x)p4=31 021 求除式和余项:q,r=deconv(conv(1 0 2,1 4),1 1 1)022 字符串的书写格式:s=student s=student name=mary;s1=name s s1=marystudent s3=name blanks(3);s s3=mary 19 student 023 交换两个数:clear clc a=1 2 3 4 5;b=6 7 8 9 10;c=a;a=b;b=c;
18、a b 24If 语句n=input(enter a number,n=);if nb max=a;else max=b;end max 026 三个数按照由大到小的顺序排列:A=15;B=24;C=45;if AB T=A;A=B;B=T;elseif AC T=A;A=C;C=T;elseif BC T=B;B=C;C=T;end A 20 B C 027 建立一个收费优惠系统:price=input(please jinput the price:price=)switch fix(price/100)case0,1 rate=0;case2,3,4 rate=3/100;case nu
19、m2cell(5:9)rate=5/100;case num2cell(10:24)rate=8/100;case num2cell(25:49)rate=10/100;otherwise rate=14/100;end price=price*(1-rate)028:while 循环语句i=0;s=0;while i=1212 s=s+i;i=i+1;end s 029,用 for 循环体语句:sum=0;for i=1:1.5:100;sum=sum+i;end sum 030 循环的嵌套s=0;for i=1:1:6;for j=1:1:8;s=s+ij;21 end;end;s 031
20、continue 语句的使用:for i=100:120;if rem(i,7)=0;continue;end;i end 032 x=input(输入 X 的值x=)if x1&x2 y=x2-1;else y=x2-2*x+1;end y 033 求阶乘的累加和sum=0;temp=1;for n=1:10;temp=temp*n;sum=sum+temp;end sum 034 对角线元素之和sum=0;a=1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 16;for i=1:4;sum=sum+a(i,i);end sum 22 035 用拟合点绘图A=12 1
21、5.3 16 18 25;B=50 80 118 125 150.8;plot(A,B)036 绘制正玄曲线:x=0:0.05:4*pi;y=sin(x);plot(x,y)037 绘制向量x=1 2 3 4 5 6;7 8 9 10 11 12;13 14 15 16 17 18 plot(x)x=0 0.2 0.5 0.7 0.6 0.7 1.2 1.5 1.6 1.9 2.3 plot(x)x=0:0.2:2*pi y=sin(x)plot(x,y,m:p)038 在正弦函数上加标注:t=0:0.05:2*pi;plot(t,sin(t)set(gca,xtick,0 1.4 3.14
22、56.28)xlabel(t(deg)ylabel(magnitude(v)title(this is a example()rightarrow 2pi)text(3.14,sin(3.14),leftarrow this zero forpi)039 添加线条标注x=0:0.2:12;plot(x,sin(x),-,x,1.5*cos(x),:);legend(First,Second,1)040 使用 hold on 函数x=0:0.2:12;23 plot(x,sin(x),-);hold on plot(x,1.5*cos(x),:);041 一界面多幅图x=0:0.05:7;y1=
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- MATLAB 编程 练习 答案 很好
限制150内