




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、同济大学 matlab 课程练习题答案关晓飞第一章 初识 matlab题目 1x1=input(x1=);x2=input(x2=);x3=input(x3=);x4=input(x4=);x5=input(x5=);x6=input(x6=);x7=input(x7=);a=x1/x5;b=x3/(x2-x1)0.85;c=1-0.36*(x4/x2)(-0.56);d=2.62*c1.5;e=(x4/x2)1.16;f=(1-d*e)/(x6*x7)0.5;y=174.42*a*b*f题目 2略题目 3 help lookfor lookfor Search all MATLAB file
2、s for keyword.lookfor XYZ looks for the string XYZ in the first comment line(the H1 line) of the HELP text in all MATLAB files found on MATLABPATH (including private directories). For all files in which amatch occurs, lookfor displays the H1 line.For example, lookfor inverse finds at least a dozen m
3、atches, including the H1 lines containing inverse hyperbolic cosine two-dimensional inverse FFT, and pseudoinverse.Contrast this with which inverse or what inverse, which run more quickly, but which probably fail to find anything because MATLAB does not ordinarily have a function inverse.lookfor XYZ
4、 -all searches the entire first comment block of each MATLAB file.In summary, WHAT lists the functions in a given directory,WHICH finds the directory containing a given function or file, and lookfor finds all functions in all directories that might havesomething to do with a given key word.题目 4n=inp
5、ut(n=);sum(1:n)prod(1:n)题目 5 linspace(0,360,9)ans =0 45 90 135 180 225 270 315 360题目 7n=input(n=)format bankn第二章矩阵的建立题目 1.spiral 产生螺旋矩阵例:spiral(3)ans=7 8 96 1 25 4 3题目 2.(1)1 2;3 4+10-2ians =12.0000 - 2.0000i14.0000 - 2.0000i11.0000 - 2.0000i13.0000 - 2.0000i(2)1 2;3 4.*0.1 0.2;0.3 0.4 ans =0.1000 0
6、.40000.90001.60003) 1 2;3 4.20 10;9 2ans =20.00003.0000(4)exp(1 2;3 4)ans =5.00000.5000%自然对数的 1、2、3、4 乘方2.7183 7.389120.0855 54.5982(5)1 2;3 4.2ans =14916(6)sum(1 2;3 4) ans =4 6(7)prod(1 2;3 4)%每一列的所有行相加ans =3(8)a,b=min(10a =10b =1(9)abs(1 2;3 4-pi)ans =2.14160.1416(10)820;30 40)%a代表每一列的最小值, b 代表该值
7、所在的行数201%绝对值1.14160.8584linspace(3,4,5)%生成 3 到 4 均匀的 5 个数ans =3.00003.2500 3.5000 3.75004.0000%提取第 2 列(11)A=1 2;3 4;sort(A(:,2) ans =24题目 3.A=1,2,3,4;4,3,2,1;2,3,4,1;3,2,4,1A =1234432123413241A(5,6)=5A =123400432100230 题目 4 示例: A=3 -1;-1 3 A =3-1 X,D=eig(A) X =-0.7071-0.7071D =20 题目 5 A =-13-0.70710
8、.7071043 -1-1 32Aans =10-6-6102.A ans =8.00000.50000.50008.0000题目 6(1)A=magic(6)A =351626192433272123253192222720828331710153053412141643629131811c=A(2,1)c =3(2)t = 2:2:6;B = A(t,:);BB =33272123258283317101543629131811(3)A(: , end,2:end-1,1)ans =241626193525327212332092222731152833171081653412143011
9、362913184(4)A(:,1 3 4 5 6)ans =356261924372123253122227208331710153034121416429131811题目 7 ones(4,5) ans =11111111111111111111rand(3,4)ans =0.81470.91340.27850.96490.90580.63240.54690.15760.12700.09750.95750.9706 eye(3)ans =100010001题目 8A=0:99;A=reshape(A,10,10)010203040506070809011121314151617181912
10、1222324252627282 9231323334353637383934142434445464748494515253545556575859561626364656667686967172737475767778797818283848586878889891929394959697989 99A=magic(3) 题目 9 A =816357492A(2,:)=A(2,:)*2A =81661014492A(1,:)=A(1,:)+A(3,:)*(-2)A =0 -17 261014492题目 10A=1,3,5;5,8,3;6,1,6;B=3,6;9,5;8,2;C=3,3,9;
11、4,0,6;D=2:6; A,Bans =135365839561682A;Cans =135583616339406A,B;Dans =13536583956168223456A=ones(6,7)A =111111111111111111111111111111111111111111题目 11for i=1:6for j=1:7A(i,j)=i+j;endendAA =2345678345678945678910567891011678910111278910111213%本题还有多种方法第三章符号计算题目 1略题目 2 sym(0,3)ans =0.3 sym(0.3)%符号工具箱得出
12、更精确的解ans =3/10题目 3 syms x s f=x5+3*x4+4*x3+2*x2+3*x+6;g=(s-1)/(s+1); f(x)=compose(f,g,x,s) f(x) =(3*(s - 1)/(s + 1) + (2*(s - 1)2)/(s + 1)2 + (4*(s - 1)3)/(s + 1)3 + (3*(s - 1)4)/(s + 1)4 + (s - 1)5/(s + 1)5 + 6 simplify(f(x) ans =19 - (72*s4 + 120*s3 + 136*s2 + 72*s + 16)/(s + 1)5题目 4 sum(sym(2).1:
13、64) ans =230题目 5f=sym(cos(4*a)-4*cos(2*a)+3);simplify(f) ans =8*sin(a)4题目 6 f=sym(3*x+2/3)10);expand(f) ans =59049*x10 + 131220*x9 + 131220*x8 + 77760*x7 + 30240*x6 + 8064*x5+ (4480*x4)/3 + (5120*x3)/27 + (1280*x2)/81 + (5120*x)/6561 + 1024/59049所以系数最大的项是 131220*x9 和 131220*x8题目 7 syms a x factor(a*
14、(sin(x)2-(2*a2-a+1)*sin(x)+2*a-1) ans =(sin(x) - 2*a + 1)*(a*sin(x) - 1)第四章极限与导数题目 1(1) syms x;lim1=limit(cos(x)-exp(-x2/2)/x4,x,0)lim1 =-1/12(2) syms x t;lim2=limit(1+2*t/x)3*x,x,inf)lim2 =Inf + imag(t)*6*i(3) syms x;lim3=limit(1/x,x,0,right)Lim3 =Inf(4) syms x;lim4=limit(2x-log(2x)-1)/(1-cos(x),x,
15、0)Lim4 =log(2)2题目 2 syms x;lim=limit(exp(x)-1-x)/x2,x,0) lim =1/2题目 3 syms x;lim=limit(x0.5-2(-1/x),x,0,right)lim =0题目 4 syms x;lim=limit(atan(x)/(1+x2),x,pi,left) lim =atan(pi)/(pi2 + 1)题目 5 y=7*x3-2*x+3;z=diff(y,2);x=1;eval(z)ans =42题目 6 syms x y;z=exp(x)*sin(2*y)+log(x)*cos(2*y);f=diff(z,y)f =2*c
16、os(2*y)*exp(x) - 2*sin(2*y)*log(x)题目 7 syms x y t;x=t2*sin(t);y=2*t*cos(t);f=diff(y)/diff(x)f =(2*cos(t) - 2*t*sin(t)/(t2*cos(t) + 2*t*sin(t)题目 8 syms x;lim=limit(3x+9x)(1/x),x,inf)lim =9题目 9 syms x;lim=limit(1+x)(1/x),x,0)lim =exp(1)题目 10 syms x;y=(x-1)*(x-2)/(x-3)/(x-4)0.5;f1=diff(y,1),f2=diff(y,2
17、),f3=diff(y,3)f1 =(x - 1)/(x - 3)*(x - 4) + (x - 2)/(x - 3)*(x - 4) - (x - 1)*(x- 4)/(2*(x- 2)/(x - 3)*(x - 4)2) - (x - 1)*(x - 2)/(x - 3)2*(x- 1)*(x - 2)/(x - 3)*(x - 4)(1/2)f2 =(2/(x - 3)*(x - 4) - (2*(x - 1)/(x - 3)*(x - 4)2) - (2*(x - 1)/(x- 3)2*(x - 4) - (2*(x - 2)/(x - 3)*(x - 4)2) - (2*(x - 2
18、)/(x - 3)2*(x- 4) + (2*(x - 1)*(x - 2)/(x - 3)*(x - 4)3) + (2*(x - 1)*(x - 2)/(x- 3)2*(x - 4)2) + (2*(x - 1)*(x - 2)/(x - 3)3*(x - 4)/(2*(x -1) *(x - 2)/(x - 3)*(x - 4)(1/2) - (x - 1)/(x - 3)*(x - 4) + (x- 2)/(x - 3)*(x - 4) - (x - 1)*(x - 2)/(x - 3)*(x - 4)2) - (x -1)*(x - 2)/(x - 3)2*(x - 4)2/(4*(
19、x - 1)*(x - 2)/(x - 3)*(x -4)(3/2)f3 =(3*(x - 1)/(x - 3)*(x - 4) + (x - 2)/(x - 3)*(x - 4) - (x - 1)*(x- 2)/(x - 3)*(x - 4)2) - (x - 1)*(x - 2)/(x - 3)2*(x -4)3)/(8*(x - 1)*(x - 2)/(x - 3)*(x - 4)(5/2)- (6/(x -3)*(x- 4)2) + 6/(x - 3)2*(x - 4) - (6*(x - 1)/(x - 3)*(x - 4)3) - (6*(x- 1)/(x - 3)2*(x -
20、4)2) - (6*(x - 1)/(x - 3)3*(x - 4) - (6*(x -2) )/(x - 3)*(x - 4)3) - (6*(x - 2)/(x - 3)2*(x - 4)2) - (6*(x - 2)/(x- 3)3*(x - 4) + (6*(x - 1)*(x - 2)/(x - 3)*(x - 4)4) + (6*(x - 1)*(x- 2)/(x - 3)2*(x - 4)3) + (6*(x - 1)*(x - 2)/(x - 3)3*(x - 4)2)+ (6*(x - 1)*(x - 2)/(x - 3)4*(x - 4)/(2*(x - 1)*(x - 2
21、)/(x -3) *(x - 4)(1/2) - (3*(x - 1)/(x - 3)*(x -4) + (x - 2)/(x - 3)*(x- 4) - (x - 1)*(x - 2)/(x - 3)*(x - 4)2) - (x - 1)*(x - 2)/(x -3)2*(x - 4)*(2/(x - 3)*(x - 4) - (2*(x - 1)/(x - 3)*(x - 4)2) -(2*(x - 1)/(x - 3)2*(x - 4) - (2*(x - 2)/(x - 3)*(x - 4)2) - (2*(x - 2)/(x - 3)2*(x - 4) + (2*(x - 1)*(
22、x - 2)/(x - 3)*(x - 4)3) + (2*(x - 1)*(x - 2)/(x - 3)2*(x - 4)2) + (2*(x - 1)*(x - 2)/(x - 3)3*(x- 4)/(4*(x - 1)*(x - 2)/(x - 3)*(x - 4)(3/2)题目 11 syms x;y=x*log(x);diff(y,10)ans = 40320/x9题目 12 syms x;y=exp(-2*x);taylor(y,x,0,order,6)ans =- (4*x5)/15 + (2*x4)/3 - (4*x3)/3 + 2*x2 - 2*x + 1题目 13 syms
23、 x;y=x/sin(x);f=taylor(y,x,2,order,5),ezplot(f)(2*(cos(2)2/sin(2)2 + 1/2)/sin(2) - cos(2)/sin(2)2)*(x - 2)2 - (cos(2)/(3*sin(2) + (cos(2)*(cos(2)2/sin(2)2 + 1/2)/sin(2)/sin(2) - (2*(cos(2)2/(3*sin(2)2) + (cos(2)*(cos(2)/(3*sin(2) + (cos(2)*(cos(2)2/sin(2)2 + 1/2)/sin(2)/sin(2) + 5/24)/sin(2)*(x- 2)4
24、 - (2*cos(2)/sin(2)2 - 1/sin(2)*(x - 2) - (x -2)3*(2*(cos(2)/(3*sin(2) + (cos(2)*(cos(2)2/sin(2)2 +1/2)/sin(2)/sin(2) - (cos(2)2/sin(2)2 + 1/2)/sin(2) + 2/sin(2)题目 14 syms x1 x2 x3 x4 x5 x6 x7;a=x1/x5;b=x3/(x2-x1)0.85;c=1-0.36*(x4/x2)(-0.56);d=2.62*c1.5;e=(x4/x2)1.16;f=(1-d*e)/(x6*x7)0.5;y=174.42*a*
25、b*f; f1=diff(y,x1);f2=diff(y,x2);f3=diff(y,x3);f4=diff(y,x4);f5=diff(y,x5);f6=diff(y,x6);f7=diff(y,x7);x1=0.1;x2=0.3;x4=0.1;x5=1.5;x6=16;x7=0.7 5; eval(f1),eval(f2),eval(f3),eval(f4),eval(f5),eval(f6),eval(f7)ans =(649*x3)/(80*(5*x3)(3/20) + (63*(5*x3)(17/20)/0ans =(62824*(5*x3)(17/20)/5967 - (649*x
26、3)/(80*(5*x3)(3/20) ans =31763/(200*(5*x3)(3/20)ans =-(*(5*x3)(17/20)/57571ans =-(21*(5*x3)(17/20)/00ans =-(137*(5*x3)(17/20)/3264ans =-(137*(5*x3)(17/20)/72第五章 程序编制题目 1略题目 2function f=fib(n)if n=1|n=2 %“| ”是或者f=1;elsef=fib(n-1)+fib(n-2);end题目 3 function a=countwords(s)d=length(s);n=1;x=0;while n0)&
27、(isempty(ounce)=1)&(isempty(kerra)=1)ounce=kilogram*1000/28.3495,kerra=kilogram*1000/0.2,endif ounce0&(isempty(kilogram)=1)&(isempty(kerra)=1) kilogram=ounce*28.3495/1000, kerra=ounce*5*28.3495 endif kerra0&(isempty(ounce)=1)&(isempty(kilogram)=1) ounce=kerra/(5*28.3495),kilogram=kerra/5000,end%每次输入
28、其中一个,输出另两个的换算结果题目 5y=input(enter a year:);m=input(enter a month:);if (mod(y,400)=0)|(mod(y,4)=0)&(mod(y,100)=0)switch m,case1,3,5,7,8,10,12nday=31;case4,6,9,11nday=30;otherwise nday=29;endelseswitch m,case1,3,5,7,8,10,12nday=31;case4,6,9,11nday=30;otherwise nday=28;end endnday=nday题目 6s=input(,s);a=
29、s(1:4);y=str2num(a);b=s(6:7);M=str2num(b);c=s(9:10);D=str2num(c);C=floor(y/100);% 世纪数Y=mod(y,100);%年份后两位 w=mod(floor(C/4)-2*C+Y+floor(Y/4)+floor(13*(M+1)/5)+D-1),7) % Zeller 公式该年的 1,2 月按 13,14 计算。题目 7m=input();if m1500)&(m4500)&(m9000)&(m35000)&(m80000t=45+300+900+6000+15750+0.45*(m-80000)endt第六章 算法
30、入门%习题一%查键盘字符对应的 ASCII 码clear,clc% 清空变量和屏幕a=input( 请输入您的要加密的字符: n,s); % 输入加密字符n=length(a);% 计算字符长度for i=1:n,if (a(i)=65 & a(i)=97 & a(i)=87 & a(i)=118 & a(i)=2A1=cell(n,1);o=0;for i=1:nA1i,1=input(one of the words:,s);endj=1;while jns=A1j,1;b=length(s);k=j+1;while k=nt=A1k,1;d=length(t);u=setxor(s,t)
31、;if (b=d)&(length(u)=2)|(b=d+1)|(d=b+1)&(length(u)0)0X(S(i,m)=0;endendfor n=1:9%列不重复if S(n,j)0X(S(n,j)=0;endendB=Aa,b;for p=1:3%宫不重复for q=1:3if B(p,q)0X(B(p,q)=0;endendendend if sum(X0)=1S(i,j)=sum(X);endendendendS %本题答案只用了书上的方法,且只能够解出书上例题难度的题目第八章 图形的绘制题目 1x=linspace(0,4*pi,8000);y1=sin(x);y2=cos(x)
32、;y4=0;plot(x,y1,k);hold on;plot(x,y2, k);xlabel( x);ylabel( y);plot(x,y4,k);hold on;plot(x,y2, k);xlabel( x);ylabel( y);plot(x,y4,;k);plot(y4,x, k);title( y1=sin(x) y2=cos(x) );x1=linspace(0,0.5*pi,1000);r)y3=sin(x1);fill(x1,pi/2,y3,0,题目 2Subplot(2,2,1);x=0:pi/60:2*pi,plot(x,sin(2*x);Subplot(2,2,2);
33、y=0:pi/60:0.499*pi;plot(y,tan(y);Subplot(2,2,3);plot(x,log(x);Subplot(2,2,4);plot(x,exp(log(10)*x);题目 3X=213,387,220,280,280,180;Pie3(x)题目 3X=1:6;Y=213,387,220,280,280,180Bar(x,y),set(gca, XTicklabel , 计算机系 ; 外语系 ; 音乐系 美术系 ; 中文系 ; 理学院 ),Set(gca, XTick ,1:6),xlabel(专业 ), ylabel( 人数 ),title(专业学生分布 )%这
34、样做出的柱状图就跟 excel 差不多题目 4x=linspace(-3,3);y=linspace(-2,2);X,Y=meshgrid(x,y); f=X.2+(abs(X).*exp(Y)./(X.4+1);Mesh(X,Y,f)% 注意矩阵维度要一样题目 5 t=linspace(0,2*pi); x=sin(t);y=t.2+exp(t);comet(x,y) 题目 6(a) theta=0:0.01:4*pi; rho=cos(3.5.*theta); polar(theta,rho);(b) theta=0:0.01:6*pi; rho=sin(theta)./theta; po
35、lar(theta,rho);(c) theta=0:0.01:2*pi;rho=1-(cos(7.*theta).3; polar(theta,rho);题目 7function qiu(R)axis(equal);% 横纵坐标相等使其看起来更圆 a=linspace(0,2*pi);b=linspace(0,2*pi);A,B=meshgrid(a,b);X=R.*cos(B).*cos(A);Y=R.*cos(B).*sin(A);Z=R.*sin(B);mesh(X,Y,Z) function xuanzhuanqumian1(a,b,c)R=linspace(1,4);T=linspace(0,2*pi);r,t=meshgrid(R,T);x=a.*r.*cos(t);y=b.*r.*sin(t);z1=c.*s
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 难点解析人教版八年级物理上册第4章光现象-光的色散综合测评试卷(含答案详解版)
- 2025年电影数字化游戏联动岗位晋升考核试卷
- 达标测试人教版八年级物理上册第6章质量与密度-质量必考点解析试题(详解)
- 难点解析人教版八年级物理上册第5章透镜及其应用专项测试试卷(详解版)
- 基于思维导图提升学生数学核心素养的实践研究
- 综合解析苏科版八年级物理上册《物态变化》定向练习试题(解析卷)
- 考点解析人教版八年级上册物理光现象《光的直线传播》同步测评试卷(解析版)
- 校长在秋冬季校园安全工作专题会议上的讲话:以“时时放心不下”之责护秋冬校园平安
- 2024年集中式饮用水水源地监测考核试卷
- 和君咨询合同(标准版)
- GB/T 37548-2019变电站设备物联网通信架构及接口要求
- FZ/T 73001-2016袜子
- 医药代表主管竞聘课件
- 水利工程建设项目招标投标课件
- 安全评价收费标准重庆市
- 管廊架施工方案
- 钢桥制造技术升级之路
- 某铁路项目工程地质勘察监理大纲
- 城市智慧排水管网监测解决方案
- 中职第四册《林黛玉进贾府》教案
- 逻辑学复习知识点
评论
0/150
提交评论