收藏 分销(赏)

MATLAB教程Ra答案全张志涌.docx

上传人:可**** 文档编号:4315824 上传时间:2024-09-05 格式:DOCX 页数:26 大小:880.64KB
下载 相关 举报
MATLAB教程Ra答案全张志涌.docx_第1页
第1页 / 共26页
MATLAB教程Ra答案全张志涌.docx_第2页
第2页 / 共26页
MATLAB教程Ra答案全张志涌.docx_第3页
第3页 / 共26页
MATLAB教程Ra答案全张志涌.docx_第4页
第4页 / 共26页
MATLAB教程Ra答案全张志涌.docx_第5页
第5页 / 共26页
点击查看更多>>
资源描述

1、目录第一章1第二章5第三章12第四章32第五章47第六章54补充题 欧拉法,龙格库塔法解方程,黑板上的题571.创建表达式%可以用syms先符号运算再带入值x=1;y=2;z=(sqrt(4*x2+1)+0.5457*exp(-0.75*x2-3.75*y2-1.5*x)/(2*sin(3*y)-1)z = -1.4345 2.计算复数x=(-1+sqrt(-5)/4;y=x+8+10jy = 7.7500 +10.5590i 3.help命令学三维曲线x=-5:0.1:5;y=x;X,Y=meshgrid(x,y);Z=(sin(sqrt(X.2+Y.2)./(sqrt(X.2+Y.2);s

2、ubplot(221);surf(X,Y,Z);colormap(cool);subplot(222);plot3(X,Y,Z,linewidth,4); %绘制三维曲线,也可以随意给定一个三维曲线的函数。如果画这个曲面,那么将绘出一族三维曲线grid on;subplot(223);meshz(X,Y,Z); %地毯绘图subplot(224);meshc(X,Y,Z); %等高线绘图4.peaks等高线(更改原函数)subplot(221);contour(peaks1,20);subplot(222);contour3(peaks1,10); %可以定义等高线条数subplot(223)

3、;contourf(peaks1,10);subplot(224);peaks1;z = 3*(1-x).2.*exp(-(x.2) - (y+1).2) . - 10*(x/5 - x.3 - y.5).*exp(-x.2-y.2) . - 1/3*exp(-(x+1).2 - y.2) 5. LOGO绘制membranelogo第一章书后习题1.合法性不合法合法不合法不合法合法2.运行命令及探讨a=sqrt(2)a = 1.4142 答:不是精确的。是一个近似。可通过改变format进行位数显示调整。例如:format long;a=sqrt(2)format short;a =1.414

4、213562373095 或可使用digits任意指定输出位数。例如:digits(50);a=sqrt(2);vpa(a)ans =1.4142135623730950488016887242096980785696718753769 常见情况下毋需太高精度。3.运行结果讨论format long;w1=a(2/3)w2=a2(1/3)w3=(a(1/3)2w1 =1.259921049894873w2 = 1.259921049894873w3 = 1.259921049894873 测试结果为相同,说明MATLAB程序执行时经过的过程相同。4.clearclfclcclear 为从内存中

5、清除变量和函数clf为清除figure中的已绘图形以及子图形clc为清除命令行窗口5.产生二维数组显然第一第二个方法可以实现。例如:s=1 2 3;4 5 6;7 8 9s = 1 2 3 4 5 6 7 8 9即是一个简便的键入矩阵的方法。第二章1 数据类型class(3/7+0.1)class(sym(3/7+0.1)class(vpa(sym(3/7+0.1),4)class(vpa(sym(3/7+0.1)ans =doubleans =symans =symans =sym 2 哪些精准?a1=sin(sym(pi/4)+exp(sym(0.7)+sym(pi/3);a2=sin(s

6、ym(pi/4)+exp(sym(0.7)*exp(sym(pi/3);a3=sin(sym(pi/4)+exp(sym(0.7)*exp(sym(pi/3);a4=sin(sym(pi/4)+exp(sym(0.7+pi/3);a5=sin(sym(pi/4)+exp(sym(0.7+pi/3);a6=sin(sym(pi/4)+sym(exp(0.7+pi/3);a7=sin(sym(pi/4+exp(0.7+pi/3);a8=sym(sin(pi/4+exp(0.7+pi/3);digits(64);vpa(a2-a1)vpa(a3-a1)vpa(a4-a1) %为精确值vpa(a5-a

7、1)vpa(a6-a1)vpa(a7-a1)vpa(a8-a1)ans =8.772689107613377606024459313047548287536202098197290121158158175e-72ans =8.772689107613377606024459313047548287536202098197290121158158175e-72ans =0.0ans =-0.0000000000000008874822716959584619522637254014249128254875650208152937300697045ans =-0.00000000000000148

8、9122128176563341755713716272780778030227615022223735634526288ans =-0.000000000000001518855593927822635897082947744411794950714383466168364259064934ans =-0.00000000000000151859755909122793880734918235619076228065004813152159311456667 可以看到,除了a4为精确,其余均存在很小的误差。其中a2与a3的误差较小,小于eps精度,故可认为为精确的。3 独立自由变量a1=sy

9、m(sin(w*t) ;a2=sym(a*exp(-X) );a3=sym(z*exp(j*th);symvar(a1,1)symvar(a2,1)symvar(a3,1)ans =wans =aans =z 6 符号解syms x k;f1=x.k;s1=symsum(f1,k,0,inf);s2=subs(f1,x,(-1/3);s3=subs(f1,x,(1/pi);s4=subs(f1,x,3);symsum(s2,k,0,inf)double(symsum(s3,k,0,inf)symsum(s4,k,0,inf)ans =3/4ans = 1.4669ans =Inf7 限定性假设

10、reset(symengine);syms k;syms x positive;f1=(2/(2*k+1)*(x-1)/(x+1)(2*k+1);f1_s=symsum(f1,k,0,inf);simplify(f1_s,steps,27,IgnoreAnalyticConstraints,true)ans =log(x) 8 符号计算syms t;yt=abs(sin(t);dydt=diff(yt,t)dydt0=limit(dydt,t,0,left)dydtpi=subs(dydt,t,(pi/2) dydt =sign(sin(t)*cos(t)dydt0 =-1dydtpi =0

11、9 积分值syms x;fx=exp(-abs(x)*abs(sin(x)fxint=int(fx,-5*pi,1.7*pi);vpa(fxint,64)fx =abs(sin(x)*exp(-x)ans =3617514.635647088707100018393465500554242735057835123431773680704 10二重积分syms x y;fxy=x2+y2;int(int(fxy,y,1,x2),x,1,2)ans =1006/105 11 绘出曲线syms t x;fx=int(sin(t)./t),t,0,x);ezplot(fx)fx4=subs(fx,x,

12、4.5)fx4 =sinint(9/2)12 积分表达式syms x;syms n positive;yn=int(sin(x).n,x,0,pi/2)yn3=subs(yn,n,1/3);vpa(yn3,32)yn =beta(1/2, n/2 + 1/2)/2ans =1.2935547796148952674767575125656 13 序列卷积syms a b n;syms k positive;xk=a.k;hk=b.k;kn=subs(xk,k,k-n)*subs(hk,k,n);yk=symsum(kn,n,0,k)yk =piecewise(a = b and b = 0,

13、bk*(k + 1), a = b or b = 0, (a*ak - b*bk)/(a - b) 所以答案为a*ak - b*bk)/(a - b)20求解solvereset(symengine)syms x y;s=solve(x2+y2-1,x*y-2,x,y)s.xs.ys = x: 4x1 sym y: 4x1 symans =(15(1/2)*i)/2 + 1/2)(1/2)/2 - (15(1/2)*i)/2 + 1/2)(3/2)/2 - (15(1/2)*i)/2 + 1/2)(1/2)/2 + (15(1/2)*i)/2 + 1/2)(3/2)/2 (1/2 - (15(

14、1/2)*i)/2)(1/2)/2 - (1/2 - (15(1/2)*i)/2)(3/2)/2 - (1/2 - (15(1/2)*i)/2)(1/2)/2 + (1/2 - (15(1/2)*i)/2)(3/2)/2ans = (15(1/2)*i)/2 + 1/2)(1/2)-(15(1/2)*i)/2 + 1/2)(1/2) (1/2 - (15(1/2)*i)/2)(1/2)-(1/2 - (15(1/2)*i)/2)(1/2) 23 求通解clear all;yso=simplify(dsolve(Dy*y*0.1+0.3*x=0,x)yso = (- 3*x2 + 2*C3)(1

15、/2)-(- 3*x2 + 2*C3)(1/2) %此题存疑holdon;clear all;reset(symengine);syms x;y1=(- 3*x2 + 2*1)(1/2);y2=-(- 3*x2 + 2*1)(1/2);h1=ezplot(y1,x,-2 2 -2 2,1);h2=ezplot(y2,x,-2 2 -2 2,1);gridon;title();warning off;axis(-2 2 -2 2);set(h1,color,r,linewidth,2);set(h2,color,r,linewidth,2);xlabel(Y);ylabel(x); %对于第二章

16、存在问题的习题的探讨2.23clear all;syms x;yso=simplify(dsolve(Dy*y*0.1+0.3*x=0,x) %此题存疑holdon;clear all;reset(symengine);syms x;y1=(- 3*x2 + 2*1)(1/2);y2=-(- 3*x2 + 2*1)(1/2);h1=ezplot(y1,x,-2 2 -2 2,1);h2=ezplot(y2,x,-2 2 -2 2,1);gridon;title();warning off;axis(-2 2 -2 2);set(h1,color,r,linewidth,2);set(h2,co

17、lor,r,linewidth,2);xlabel(Y);ylabel(x); yso =(- 3*x2 + 2*C3)(1/2)-(- 3*x2 + 2*C3)(1/2)%以上方法可以绘出正常的横坐标为y纵坐标为x的图像,但发现在y=0处x延伸至正负无穷。h1=ezplot(y1,-2 2 -2 2,1);h2=ezplot(y2,-2 2 -2 2,1);%以上方法绘出的图像存在一个空隙,且默认为y-x图像。reset(symengine);syms x y S;S = dsolve(Dy*y/5+x/4=0,x);ezplot(subs(y2-(S(1)2, C3, 1),-2,2 -2

18、,2,2);grid on;%用椭圆方程绘图不产生间隙24 一阶微分方程syms a b;ys=dsolve(Dy-a*x2-b*x=0,y(0)=2,x)ys =(x2*(3*b + 2*a*x)/6 + 2 25 边值问题fs=dsolve(Df-3*f=4*g,Dg+4*f=3*g,f(0)=0,g(0)=1)fs = g: 1x1 symf: 1x1 sym fs.gfs.fans =cos(4*t)*exp(3*t)ans =sin(4*t)*exp(3*t) 第三章3.行下标列下标rng(default);A=rand(3,5);L=A0.5 L = 1 1 0 1 1 1 1 1

19、 0 0 0 0 1 1 1 a,b=find(L=1) IND=sub2ind(size(A),a,b)IND = 1 2 4 5 8 9 10 12 13 15 4.循环运算、数组运算t=0:0.1:10;N=length(t); y1=zeros(size(t); for k=1:N y1(k)=1-exp(-0.5*t(k)*cos(2*t(k);endplot(t,y1);xlabel(t);ylabel(y1); y2=1-exp(-0.5*t).*cos(2*t); plot(t,y2);xlabel(t);ylabel(y2); 5.回答问题clear all;A=magic(

20、3);B=rand(3);A*BB*Aans = 5.4072 11.5771 3.0037 6.3884 10.3215 4.9680 2.7058 7.5337 4.8496ans = 2.5916 3.8303 5.2097 3.4833 5.6313 3.6800 10.9646 9.0086 12.3554 相同,对于矩阵而言对位相乘无差异不相同,点乘与矩阵乘法进行的不是同一种运算。不相同,左乘右乘运算不同。相同,A左点除B等同于B右点除A,均是对位计算。不相同,左除右除运算亦不相同。A*AB-BA*(AB)-BA*(A*inv(B)-B ans = -0.0562 -0.6902

21、-0.0436 -0.1051 -0.3282 -0.4311 -0.8011 -0.9350 -0.3763ans =1.0e-15 * 0 -0.1110 -0.0278 0 0 0 0 0.1110 0ans = -80.2971 65.0383 107.2212 -8.0299 91.2626 70.5679 -66.2535 153.4898 66.4342 不相同。第二个更接近0。具体原理需要参考线性代数书有点忘了。Aeye(3)eye(3)/A ans = 0.1472 -0.1444 0.0639 -0.0611 0.0222 0.1056 -0.0194 0.1889 -0.

22、1028ans =0.1472 -0.1444 0.0639 -0.0611 0.0222 0.1056 -0.0194 0.1889 -0.1028 相同。因为对于对角阵,二者均可化为同一形式。6.结果不同A=1 2; 3 4;B1=A.(0.5)B2=0.5.AB3=A(0.5)B4=0.5A B1 = 1.0000 1.4142 1.7321 2.0000B2 = 0.5000 0.2500 0.1250 0.0625B3 = 0.5537 + 0.4644i 0.8070 - 0.2124i 1.2104 - 0.3186i 1.7641 + 0.1458iB4 = 0.9910 -0

23、.4422 -0.6634 0.3276 A1=B1.*B1A3=B3*B3norm(A1-A3,fro)A1 = 1.0000 2.0000 3.0000 4.0000A3 = 1.0000 + 0.0000i 2.0000 + 0.0000i 3.0000 - 0.0000i 4.0000 + 0.0000ians = 1.2831e-15 可见误差在eps量级,可以认为相等。7.绘出图形x=-3*pi:pi/15:3*pi;y=x;X,Y=meshgrid(x,y); warning off; Z=sin(X).*sin(Y)./X./Y;共有10个非数数据。surf(X,Y,Z)sha

24、dinginterpx=-3*pi:pi/15:3*pi;Lx=(x=0);xx=x+Lx*realmin;y=xx;X,Y=meshgrid(xx,y); warning off; Z=sin(X).*sin(Y)./X./Y;surf(X,Y,Z)shadinginterp即消除零点处的断点即可8.两种思路%第二种思路function z=zpoly_z(x,y)ifx+y-1 & x+y=1z=0.758*exp(-y.2-6*x.2);else z=0.546*exp(-0.75*y.2-3.75*x.2-1.5*x);end x=-1.5:0.1:1.5;y=-3:0.1:3;X,Y

25、=meshgrid(x,y);Z=zpoly_z(X,Y);surf(X,Y,Z);%第一种思路x=-1.5:0.1:1.5;y=-3:0.2:3;LX=length(x);LY=length(y);for ii=1:LXforjj=1:LYif x(ii)+y(jj)-1 & x(ii)+y(jj)=1z=0.758*exp(-y.2-6*x.2);else z=0.546*exp(-0.75*y.2-3.75*x.2-1.5*x);endendendX,Y=meshgrid(x,y);Z=zpoly_z(X,Y);surf(X,Y,Z); %其实for循环完全无意义9.矩阵计算%第一问老师

26、取消rng defaultA=randn(50,70)+1i*randn(50,70);B=randn(70,60)+1i*randn(70,60);C=randn(50,60)+1i*randn(50,60);D=randn(60,1)+1i*randn(60,1);G=(A*B-C)*DGr=real(G),70,70Gi=imag(G)Gn=norm(G,2)G = 1.0e+02 * -0.1776 + 1.9914i 0.6088 + 0.3316i -0.1340 - 0.8615i 0.0752 - 0.0759i -0.1171 - 1.8169i 0.2005 - 1.454

27、0i -1.4501 + 0.1897i 0.6445 + 0.1657i -1.0651 + 0.1191i 0.3301 - 0.0450i -1.4338 + 0.8707i -0.9491 + 1.4840i 1.1314 + 1.2751i -0.5158 - 0.0725i -0.2746 + 0.2518i -1.0279 - 0.8409i -1.1161 - 2.3362i 0.1346 + 1.3500i 0.4220 - 1.2839i 0.2650 - 0.2849i -1.0212 + 0.5374i 0.0563 + 0.4151i -1.9074 - 0.2448

28、i 0.1645 + 1.2071i 1.1870 + 0.0085i 1.2304 + 0.6672i 0.3303 - 1.6027i -0.5728 - 0.5519i 0.3738 + 0.2863i -0.6682 - 0.7565i 1.6063 + 1.2886i 0.6994 - 1.3377i 0.6523 + 0.0318i -0.2143 - 2.8209i 1.7026 - 0.1371i 0.9285 + 1.5852i -0.7550 - 0.2427i -1.3879 - 1.8978i -0.5266 - 0.8334i -0.0849 + 0.1680i 1.

29、1590 + 0.2109i -1.8938 + 0.6709i 0.3406 - 1.8211i -1.0916 - 1.8076i 0.2062 - 1.4363i 1.3679 + 0.2061i -0.4541 + 0.8056i 1.3574 + 0.8773i -0.1071 + 0.0948i 0.1042 + 2.2812iGr = -17.7553 60.8848 -13.4003 7.5175 -11.7073 20.0458 -145.0055 64.4517 -106.5069 33.0077 -143.3779 -94.9055 113.1368 -51.5804 -

30、27.4560 -102.7914 -111.6150 13.4596 42.2009 26.5006 -102.1225 5.6295 -190.7388 16.4525 118.6963 123.0361 33.0336 -57.2817 37.3849 -66.8175 160.6261 69.9436 65.2278 -21.4319 170.2597 92.8549 -75.5045 -138.7923 -52.6574 -8.4902 115.9030 -189.3844 34.0593 -109.1584 20.6169 136.7896 -45.4089 135.7386 -1

31、0.7050 10.4240Gi = 199.1404 33.1590 -86.1452 -7.5887 -181.6856 -145.4039 18.9686 16.5731 11.9053 -4.5021 87.0651 148.4022 127.5072 -7.2483 25.1791 -84.0887 -233.6194 135.0018 -128.3931 -28.4923 53.7385 41.5139 -24.4788 120.7113 0.8532 66.7238 -160.2738 -55.1871 28.6287 -75.6522 128.8596 -133.7671 3.

32、1772 -282.0866 -13.7111 158.5203 -24.2673 -189.7767 -83.3384 16.7992 21.0869 67.0898 -182.1134 -180.7631 -143.6344 20.6149 80.5622 87.7339 9.4764 228.1237Gn = 1.0253e+03 y2=1-exp(-0.5*t).*cos(2*t); plot(t,y2);xlabel(t);ylabel(y2); 5.回答问题clear all;A=magic(3);B=rand(3);A*BB*Aans = 5.4072 11.5771 3.003

33、7 6.3884 10.3215 4.9680 2.7058 7.5337 4.8496ans = 2.5916 3.8303 5.2097 3.4833 5.6313 3.6800 10.9646 9.0086 12.3554 相同,对于矩阵而言对位相乘无差异不相同,点乘与矩阵乘法进行的不是同一种运算。不相同,左乘右乘运算不同。相同,A左点除B等同于B右点除A,均是对位计算。不相同,左除右除运算亦不相同。A*AB-BA*(AB)-BA*(A*inv(B)-B ans = -0.0562 -0.6902 -0.0436 -0.1051 -0.3282 -0.4311 -0.8011 -0.93

34、50 -0.3763ans =1.0e-15 * 0 -0.1110 -0.0278 0 0 0 0 0.1110 0ans = -80.2971 65.0383 107.2212 -8.0299 91.2626 70.5679 -66.2535 153.4898 66.4342 不相同。第二个更接近0。具体原理需要参考线性代数书有点忘了。Aeye(3)eye(3)/A ans = 0.1472 -0.1444 0.0639 -0.0611 0.0222 0.1056 -0.0194 0.1889 -0.1028ans =0.1472 -0.1444 0.0639 -0.0611 0.0222

35、 0.1056 -0.0194 0.1889 -0.1028 相同。因为对于对角阵,二者均可化为同一形式。6.结果不同A=1 2; 3 4;B1=A.(0.5)B2=0.5.AB3=A(0.5)B4=0.5A B1 = 1.0000 1.4142 1.7321 2.0000B2 = 0.5000 0.2500 0.1250 0.0625B3 = 0.5537 + 0.4644i 0.8070 - 0.2124i 1.2104 - 0.3186i 1.7641 + 0.1458iB4 = 0.9910 -0.4422 -0.6634 0.3276 A1=B1.*B1A3=B3*B3norm(A1

36、-A3,fro)A1 = 1.0000 2.0000 3.0000 4.0000A3 = 1.0000 + 0.0000i 2.0000 + 0.0000i 3.0000 - 0.0000i 4.0000 + 0.0000ians = 1.2831e-15 可见误差在eps量级,可以认为相等。7.绘出图形x=-3*pi:pi/15:3*pi;y=x;X,Y=meshgrid(x,y); warning off; Z=sin(X).*sin(Y)./X./Y;共有10个非数数据。surf(X,Y,Z)shadinginterpx=-3*pi:pi/15:3*pi;Lx=(x=0);xx=x+Lx

37、*realmin;y=xx;X,Y=meshgrid(xx,y); warning off; Z=sin(X).*sin(Y)./X./Y;surf(X,Y,Z)shadinginterp即消除零点处的断点即可8.两种思路%第二种思路function z=zpoly_z(x,y)ifx+y-1 & x+y=1z=0.758*exp(-y.2-6*x.2);else z=0.546*exp(-0.75*y.2-3.75*x.2-1.5*x);end x=-1.5:0.1:1.5;y=-3:0.1:3;X,Y=meshgrid(x,y);Z=zpoly_z(X,Y);surf(X,Y,Z);%第一

38、种思路x=-1.5:0.1:1.5;y=-3:0.2:3;LX=length(x);LY=length(y);for ii=1:LXforjj=1:LYif x(ii)+y(jj)-1 & x(ii)+y(jj)=1z=0.758*exp(-y.2-6*x.2);else z=0.546*exp(-0.75*y.2-3.75*x.2-1.5*x);endendendX,Y=meshgrid(x,y);Z=zpoly_z(X,Y);surf(X,Y,Z); %其实for循环完全无意义9.矩阵计算%第一问老师取消rng defaultA=randn(50,70)+1i*randn(50,70);B

39、=randn(70,60)+1i*randn(70,60);C=randn(50,60)+1i*randn(50,60);D=randn(60,1)+1i*randn(60,1);G=(A*B-C)*DGr=real(G),70,70Gi=imag(G)Gn=norm(G,2)G = 1.0e+02 * -0.1776 + 1.9914i 0.6088 + 0.3316i -0.1340 - 0.8615i 0.0752 - 0.0759i -0.1171 - 1.8169i 0.2005 - 1.4540i -1.4501 + 0.1897i 0.6445 + 0.1657i -1.0651 + 0.1191i 0.3301 - 0.0450i -1.4338 + 0.8707i -0.9491 + 1.4840i 1.1314 + 1.2751i -0.5158 - 0.0725i -0.2746 + 0.2518i -1.0

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服