MATLAB课后习题答案

上传人:痛*** 文档编号:206728200 上传时间:2023-05-04 格式:PDF 页数:22 大小:2.40MB
收藏 版权申诉 举报 下载
MATLAB课后习题答案_第1页
第1页 / 共22页
MATLAB课后习题答案_第2页
第2页 / 共22页
MATLAB课后习题答案_第3页
第3页 / 共22页
资源描述:

《MATLAB课后习题答案》由会员分享,可在线阅读,更多相关《MATLAB课后习题答案(22页珍藏版)》请在装配图网上搜索。

1、%Page20,ex 1(5)等于exp(1 ),exp(2);exp(3),exp(4)3=1*3,8=2*4(8)a 为各列最小值,b 为最小值所在的行号(10)1=4,false,2=3,false,3=2,ture,4=l,ture(H)答案表明:编址第2 元素满足不等式(30=20)和编址第4 元素满足不等式(40=10)(12)答案表明:编址第2 行 第 1 列元素满足不等式(30=20)和编址第2 行第2 列元素满足不等式(40=10)%Page20,ex2(l)a,b,c 的值尽管都是1,但数据类型分别为数值,字符,逻辑,注意a与 c 相等,但他们不等于b(2)double(f

2、un)输出的分别是字符a,b,s,(,x,)的 ASCII码%Page20,ex3 r=2;p=0.5;n=12;T=log(r)/n/log(1+0.01 *p)T=11.5813%Page20,ex4 x=-2:0.05:2;f=x.A4-2.Ax;ffmin,min_indexl=min(f)fmin=-1.3907%最小值 min_index=54%最小值点编址 x(min_index)ans=0.6500%最小值点 fl,xl_index=min(abs(f)%求近似根一绝对值最小的点fl=0.0328 xl_index=24 x(xl_index)ans=-0.8500 x(xl_

3、index)=;f=x.A4-2.Ax;%删去绝对值最小的点以求函数绝对值次小的点 f2,x2_index=min(abs(f)%求另一近似根-函数绝对值次小的点f2=0.0630 x2_index=65 x(x2_index)ans=1.2500%Page20,ex5 z=magic(10)z=92 99 1 8 15 67 74 51 58 4098 80 7 14 16 73 55 57 64 41481 88 20 22 54 56 63 70 4785 87 1921 3 60 62 69 71 2886 93 25 2 9 61 68 75 52 3417 24 76 83 90

4、42 49 26 33 6523 5 82 89 91 48 30 32 39 6679 6 13 95 97 29 31 38 45 7210 12 94 96 78 35 37 44 46 5311 18 100 77 84 36 43 50 27 59 sum(z)ans=505 505 505 505 505 505 505 505 505 505 sum(diag(z)ans=505 z(:,2)/sqrt(3)ans=57.157746.188046.765450.229553.693613.85642.88683.46416.928210.3923 z(8,:)=z(8,:)+z

5、(3,:)z=92 99 1 8 15 67 74 51 58 4098 80 7 14 16 73 55 57 64 41481 88 20 22 54 56 63 70 4785 87 1921 3 60 62 69 71 2886 93 25 2 9 61 68 75 52 3417 24 76 83 90 42 49 26 33 6523 5 82 89 91 48 30 32 39 6683 87 101 115 119 83 87 101 115 11910 12 94 96 78 35 37 44 46 5311 18 100 77 84 36 43 50 27 59%Page

6、40 ex 1先在编辑器窗口写下列M 函数,保存为eg2.mfunction xbar,s=ex2_l(x)n=length(x);xbar=sum(x)/n;s=sqrt(sum(x.A2)-n*xbarA2)/(n-1);例如x=81 70 65 51 76 66 90 87 61 77;xbar,s=ex2_l(x)xbar=72.4000 s=12.1124%Page 40 ex2 s=log(l);n=0;while sek=k+l;F(k)=F(k-l)+F(k-2);x=F(k)/F(k-l);end a,x,k 计算至 k=21 可满足精度%Page 40 ex4 clear;

7、tic;s=0;for i=l:1000000s=s+sqrt(3)/2Ai;end s,toc tic;s=0;i=l;while il.l)+x.*(x=-Ll)-Ll*(xl);p=p+b*exp(-y.A2-6*x.A2).*(x+y-1 ).*(x+y=l);p=p+a*exp(-0.75*y.A2-3.75*x.A2+1.5*x).*(x+y x=A b x=2.3 83 01.4 89 42.0 2 1 3%E xerc ise 2(2)A=4 -3 3;3 2 -6;1 -5 3 ;b=-l;-2;l;ra n k(A),ra n k(A,b J)a n s=3 a n s=3

8、%可见方程组唯一解 x=A b x=-0.4 7 0 6-0.2 9 4 10%E xerc ise 2(3)A=4 1;3 2;1 -5;b=l;l;l;ra n k(A),ra n k(A,b )a n s=2 a n s=3%可见方程组无解 x=A b x=0.3 3 1 1-0.1 2 1 9%最小二乘近似解%E xerc ise 2(4)2 3 1;注意 b 的写法 ra n k(a),ra n k(a,b )a n s=3 a n s=3%ra n k(a)=ra n k(a,b )x=xO;fo r i=l:1 0 0 0,x=a*x;en d,x x=0.83 3 30.1 6

9、67 v,e=eig(a)v=0.9 80 6-0.7 0 7 1 0.1 9 61 0.7 0 7 1 e=1.0 0 0 0 00 0.9 4 0 0 v(:,l)./x a n s=1.1 7 671.1 7 67%成比例,说明x是最大特征值对应的特征向量%E xerc ise 5%用到公式(3.1 1)(3.1 2)B=6,2,1 ;2,2 5,1,0.2;3,0.2,1.8;x=2 5 5 2 0 ,;C=B/d ia g(x)C=0.2 4 0 0 0.4 0 0 0 0.0 50 00.0 9 0 0 0.2 0 0 0 0.0 1 0 00.1 2 0 0 0.0 4 0 0

10、0.0 9 0 0 A=eye(3,3)-CA=0.7 60 0 -0.4 0 0 0 -0.0 50 0 -0.0 9 0 0 0.80 0 0 -0.0 1 0 0 -0.1 2 0 0 -0.0 4 0 0 0.9 1 0 0 D=1 7 1 7 1 7 ,;x=A Dx=3 7.569 6 2 5.7 862 2 4.7 69 0%E xerc ise 6(1)a=4 1 -1;3 2 -6;1 -5 3 ;d et(a),in v(a),v,d =eig(a)a n s=-9 4a n s=0.2 553 -0.0 2 1 3 0.0 4 2 6 0.1 59 6-0.1 3 83

11、-0.2 2 3 4 0.1 80 9 -0.2 2 3 4 -0.0 53 2v=0.0 1 85-0.9 0 0 9 -0.3 0 66-0.7 69 3 -0.1 2 4 0 -0.7 2 4 8-0.63 86-0.4 1 58 0.61 7 0d =-3.0 52 7 0 00 3.67 60 00 0 8.3 7 66%E xerc ise 6(2)a=1 1 -l;0 2 -1;-1 2 O ;d et(a),in v(a),v,d =eig(a)a n s=1a n s=2.0 0 0 0 -2.0 0 0 0 1.0 0 0 0 1.0 0 0 0 -1.0 0 0 0 1.

12、0 0 0 0 2.0 0 0 0 -3.0 0 0 0 2.0 0 0 0v=-0.57 7 3 0.57 7 4 +O.O O O O i 0.57 7 4 -O.O O O O i-0.57 7 3 0.57 7 4 0.57 7 4 -0.57 7 4 0.57 7 3 -O.O O O O i0.57 7 3 +O.O O O O id =1.0 0 0 0 0 00 1.0 0(X)+O.O O O O i 00 0 1.0 0 0 0-O.O O O O i%E xerc ise 6(3)A=5 7 6 5;7 1 0 8 7;6 8 I 0 9;5 7 9 1 0 A =57

13、657 1 0 8768 1 0 95 7 9 1 0 d et(A),in v(A),v,d =eig(A)a n s=1a n s=68.0 0 0 0 -4 1.0 0 0 0 -1 7.0 0 0 0 1 0.0 0 0 0 -4 1.0 0 0 0 2 5.0 0 0 0 1 0.0 0 0 0 -6.0 0 0 0 -1 7.0 0 0 0 1 0.0 0 0 05.0 0 0 0 -3.0 0 0 0 1 0.0 0 0 0 -6.0 0 0 0 -3.0 0 0 0 2.0 0 0 0v=0.83 0 4 0.0 9 3 3 0.3 9 63 0.3 80 3 -0.50 1

14、6-0.3 0 1 7 0.61 4 9 0.52 86-0.2 0 86 0.7 60 3 -0.2 7 1 6 0.552 00.1 2 3 7 -0.567 6-0.62 54 0.52 0 9d =0.0 1 0 2 0 0 0 0 0.84 3 1 0 0 0 0 3.8581 0 0 0 0 3 0.2 887%E xerc ise 6(4)(以 n=5 为例)%关键是矩阵的定义%方法一(三个fo r)n=5;fo r i=l:n,a(i,i)=5;en dfo r i=1 :(n-1 ),a(i,i+l)=6;en dfo r i=l:(n-l),a(i+1 4)=1 ;en d

15、a%方法二(一个fo r)n=5;a=zeros(n,n);a(l,l:2)=5 6;for i=2:(n-1 ),a(i,i-1 ,i,i+1 )=1 5 6;enda(n,n-l n)=l 5;a%方 法 三(不用for)n=5;a=diag(5*ones(n,1);b=diag(6*ones(n-1,1);c=diag(ones(n-1,1);a=a+zeros(n-l,l),b;zeros(l,n)+zeros(1 ,n);c,zeros(n-1J)%下列计算 det(a)ans=665inv(a)ans=0.3173-0.5865 1.0286-1.6241 1.9489-0.097

16、7 0.4887-0.8571 1.3534-1.62410.0286-0.1429 0.5429-0.8571 1.0286-0.0075 0.0376-0.1429 0.4887-0.58650.0015-0.0075 0.0286-0.0977 0.3173v,d=eig(a)v=-0.7843-0.7843-0.9237 0.9860-0.9237 0.5546-0.5546-0.3771-0.0000 0.3771-0.2614-0.2614 0.0000-0.1643 0.0000 0.0924-0.0924 0.0628-0.0000-0.0628-0.0218-0.0218 0

17、.02570.0274 0.0257d=0.7574 0 0 0 00 9.2426 0000 0 7.4495 0 0000 5.0000 00 0 0 0 2.5505%Exercise 7(1)a=4 1 -1;32-6;1-5 3;v,d=eig(a)v=0.0185-0.9009-0.3066-0.7693-0.1240-0.7248-0.6386-0.4158 0.6170d=-3.0527 0 00 3.6760 00 0 8.3766 det(v)ans=0.9255%v行列式正常,特征向量线性相关,可对角化 inv(v)*a*v%验算ans二-3.0527 0.0000-0.

18、00000.0000 3.6760-0.0000-0.0000-0.0000 8.3766 v2,d2=jordan(a)%也可用 jordanv2=0.0798 0.0076 0.9127 0.1886-0.3141 0.1256-0.1605-0.2607 0.4213%特征向量不同 d2=8.3766 000-3.0527-O.OOOOi 00 0 3.6760+O.OOOOi v2a*v2 ans=8.3766 0 0.0000 0.0000-3.0527 0.0000 0.0000 0.0000 3.6760 v(:,l)./v2(:,2)%对应相同特征值的特征向量成比例ans=2.

19、4491 2.4491 2.4491%Exercise 7(2)a=l 1 2 0;v,d=eig(a)v=-0.5773 0.5774+O.OOOOi 0.5774-O.OOOOi-0.5773 0.5774 0.5774-0.5774 0.5773-O.OOOOi 0.5773+O.OOOOid=1.0000000 1.0000+O.OOOOi 000 1.0000-O.OOOOi det(v)ans=-5.0566e-028-5.1918e-017i%v的行列式接近0,特征向量线性相关,不可对角化 v,d=jordan(a)I 0 11 0 01 -1 0d=1 1 00 1 10 0

20、1%jordan标准形不是对角的,所以不可对角化%Exercise 7(3)A=5 7 6 5;7 10 8 7;6 8 10 9;5 7 9 10A=57657 108768 1095 7 9 10 v,d=eig(A)v=0.8304 0.0933 0.3963 0.3803-0.5016-0.3017 0.6149 0.5286-0.2086 0.7603-0.2716 0.55200.1237-0.5676-0.6254 0.5209d=0.0102 0 000 0.8431 000 0 3.8581 0000 30.2887inv(v)*A*vans=0.0102 0.0000-0.

21、0000 0.0000 0.0000 0.8431-0.0000-0.0000-0.0000 0.0000 3.8581-0.0000-0.0000-0.0000 0 30.2887%本题用 jordan 不行,原因未知%Exercise7(4)参考 6(4)和 7(1),略%Exercise 8 只有对称,且特征值全部大于零,所以是正定矩阵.%Exercise 9(1)a=4-3 1 3;2-1 3 5;1-1-1-1;3-2 3 4;7-6-7 0 rank(a)ans=3 rank(a(I:3,:)ans=2 rank(a(l 2 4,:)%1,2,4 行为最大无关组 ans=3 b=a

22、(1l 2 4,:)*;c=a(3 5,:),;bc%线性表示的系数 ans=0.5000 5.0000-0.5000 1.00000-5.0000%Exercise 10 a=l-2 2;-2-2 4;2 4-2v,d=eig(a)v=0.3333 0.9339-0.12930.6667-0.3304-0.6681-0.6667 0.1365-0.7327 d=-7.0000000 2.000000 0 2.0000 v*vans=1.0000 0.0000 0.00000.0000 1.0000 00.0000 0 1.0000%v确实是正交矩阵%Exercise 11%设经过6 个电阻的

23、电流分别为i l,i 6.列方程组如下%20-2il=a;5-3i2=c;a-3i3=c;a-4i4=b;c-5i5=b;b-3i6=0;%il=i3+i4;i5=i2+i3;i6=i4+i5;%计 算如下A=l 0 0 2 0 0 0 0 0;0 0 1 03 0000;1 0-1 00-3 000;1 -1 0 0 0 0-4 0 0;0-1 1 000 0-5 0;0 1 000 0 0 0-3;0 0 0 1 0-1-1 0 0;0 0 0 0-l-1 0 1 0;0 0 0 0 0 0-1 -1 1;b=20 5 0 0 0 0 0 0 0,;Ab13.3453 6.4401 8.5

24、420 3.3274-1.1807 1.6011 1.7263 0.4204 2.1467%Exercise 12 A=l 2 3;4 5 6;7 8 0;left=sum(eig(A),right=sum(trace(A)left=6.0000 right=left=prod(eig(A),right=det(A)%原题有错,(-1)八 n 应删去 left=27.0000 right=27 fA=(A-p(1 )*eye(3,3)*(A-p(2)*eye(3,3)*(A-p(3)*eye(3,3)fA=1.0e-012*0.0853 0.1421 0.02840.1421 0.1421 0

25、-0.0568-0.1137 0.1705 norm(fA)%f(A)范数接近 Oans=2.9536e-013%Exercise 1(1)roots(I 1 1J)%Exercise 1(2)roots(3 0-4 0 2-1)%Exercise 1(3)p=zeros(l,24);p(l 17 18 22)=5-6 8-5;roots(p)%Exercise 1(4)pl=2 3;p2=conv(p 1,pl);p3=conv(pl,p2);p3(end)=p3(end)-4;%原 p3 最后一个分量-4roots(p3)%Exercise 2fun=inline(x*log(sqrt(x

26、A2-1 )+x)-sqrt(xA2-1fzero(fun,2)%Exercise 3fun=inline(,xA4-2Ax,);fplot(fun,-2 2);grid on;fzero(fun,-l),fzero(fun,l),fminbnd(fun,0.5J.5)%Exercise 4fun=inline(,x*sin(l/x),x,);fplot(fun,-0.1 0.1);x=zeros(l,10);for i=l:10,x(i)=fzero(fun,(i-0.5)*0.01);end;x=x,-x%Exercise 5fun=inline(19*x(1)八 2+36*x(2)八 2

27、+4*x(3)八 2-36;x(1)八 2 2*x(2)八 2-20*x(3);16*x(1 )-x(1 )A3-2*x(2)A2-16*x(3)A27xr);a,b,c=fsol ve(fun,0 0 0)%Exercise 6fun=(x)x(l)-0.7*sin(x(l)-0.2*cos(x(2),x(2)-0.7*cos(x(l)+0.2*sin(x(2);a,b,c=fsolve(fun,0.5 0.5)%Exercise 7clear;close;t=0:pi/100:2*pi;xl=2+sqrt(5)*cos(t);yl=3-2*x 1+sqrt(5)*sin(t);x2=3+s

28、qrt(2)*cos(t);y2=6*sin(t);plot(xl,yl,x2,y2);grid on;%作图发现4 个解的大致位置,然后分别求解yl=fsolve(I(x(l)-2)A2Xx(2)-3+2*x(l)A2-5,2*(x(l)-3)A2+(x(2)/3)A2-4;1.5,2)y2=fsolveC(x(1 )-2)A2+(x(2)-3+2*x(1 )A2-5,2*(x(1 )-3)A2+(x(2)/3)A2-4J;1.8,-2)y3=fsolveC(x(l)-2)A2+(x(2)-3+2*x(l)A2-5,2*(x(l)-3)A2+(x(2)/3)A2-4;3.5,-5)y4=fs

29、olveC(x(l)-2)A2+(x(2)-3+2*x(l)A2-5,2*(x(l)-3)A2+(x(2)/3)A2-4,4,-4)%Exercise 8(1)clear;fun=inline(,x.A2.*sin(x.A2-x-2)1);fplot(fun,-2 2);grid on;%作图观察x(l)=-2;x(3)=fminbnd(fun,-1 ,-0.5);x(5)=fminbnd(fun,1,2);fun2=inline(x.八 2.*sin(x.A2-x-2);x(2)=fminbnd(fun2,-2,-1);x(4)=fminbnd(fun2,-0.5,0.5);x(6)=2fe

30、val(fun,x)%答案:以上x(l)(3)(5)是局部极小,x(2)(4)(6)是局部极大,从最后一句知道x(l)全局最小,x(2)最大。%Exercise 8(2)clear;fun=inline(,3*x.A5-20*x.A3+1 O);fplot(fun,-3 3);grid on;%作图观察x =-3;x(3)=fminsearch(fun,2.5);fun2=inlineJ(3*x520*xC3+10);x(2)=fminsearch(fun2,-2.5);x(4)=3;feval(fun,x)%Exercise 8(3)fun=inline(abs(xA3-x 八 2-x-2)

31、;fplot(fun,0 3);grid on;%作图观察fminbnd(fun,1.5,2.5)fun2=inline(-abs(xA3-xA2-x-2);fminbnd(fun2,0.5,1.5)%Exercise 9close;x=-2:0.1:l;y=-7:0.1:l;x,y=meshgrid(x,y);z=y.A3/9+3*x.A2.*y+9*x.A2+y.A2+x.*y4-9;mesh(x,y,z);grid on;%作图观察fun=inline(,x(2)A3/9+3*x(1 )A2*x(2)+9*x(1 )A2+x(2)A2+x(1 )*x(2)+9);x=fminsearch

32、(fun,O 0)%求极小值fun2=inline(-(x(2)A3/9+3*x(1 )A2*x(2)+9*x(1 )A2+x(2)A2+x(1 )*x(2)+9),);x=fminsearch(fun2,0-5)%求极大值%Exercise 10clear;t=0:24;c=l15 14 14 14 14 15 16 18 20 22 23 25 28.31 32 31 29 27 25 24 22 20 18 17 16;p2=polyfit(t,c,2)p3=polyfit(t,c,3)fun=inline(a(l)*exp(a(2)*(t14).A2),a,t);a=lsqcurvef

33、it(fun,O O,t,c)%初 值 可 以 试 探f=feval(fun,a,t)norm(f-c)%拟合效果 plot(t,c,t,f)%作图检验fun2=inline(,b(l)*sin(pi/12*t+b(2)+20,b7t,);%原 题修改 f(x)+20b=lsqcurvefit(fun2,0 O,t,c)figure f2=feval(fun2,b,t)norm(f2-c)%拟合效果 plot(t,c,t,f2)%作图检验%Exercise 11 fun=inline(lx)*sqrt(10.52+x)-3.06*x*sqrt(l+x)*sqrt(5);x=fzero(fun,

34、0,1)%Exercise 12 r=5.04/12/100;N=20*12;x=7500*180%房屋总价格 y=x*0.3%首 付 款 额x0=x-y%贷款总额 a=(l+r)八 N*r*x0/(l+r)八 Nl)%月付还款额 r 1 =4.05/12/100;x 1 =10*10000;%公积金贷款 al=(l+rl)AN*rl*xl/(l+rl)AN-l)x2=x0-xl%商业贷款a2=(l+r)八 N*r*x2/(1 +r)AN-l)a=a 1 +a2%Exercise 13%列 方 程 lh*R八 2+(pi-2*th)*rA2-R*r*sin(th)=pi*i 八 2/2%化简

35、得sin(2*th)-2*th*cos(2*th)=pi/2%以 下 Matlab 计 算 clear;fun=inline(sin(2*th)-2:1:th*cos(2*th)-pi/2,th,)th=fsolve(fun,pi/4)R=20*cos(th)%Exercise 14%先在 Editor 窗口写 M 函数保存 function x=secant(fname,xO,x 1 ,e)whileabs(x0-x l)e,x=x 1 -(x 1 -xO)*feval(fname,x l)/(feval(fname,x 1 )-feval(fname,xO);x0=xl;xl=x;end%

36、再在 指 令 窗 口 fun=inline(x*log(sqrt(x八 2-l)+x)-sqrt(xA2-l)-0.5*x);secant(fun,l,2,le-8)%Exercise 15%作系数为a,初值为xo,从第m 步到第n 步迭代过程的M 函数:function f=ex4_ 15fun(a,x0,m,n)x(1 )=x0;y(l)=a*x(l)+l;x(2)=y(l);if mm,plot(x(i),x(i),x(i+1 ),y(i-1 ),y(i),y(i);end end hold off;%M 脚 本 文 件subplot(2,2,1 );ex4_l 5fun(0.9,1,1

37、,20);subplot(2,2,2);ex4_ 15fun(-0.9,l,l,20);subplot(2,2,3);ex4_l5fun(1.1,1,1,20);subplot(2,2,4);ex4_l5fun(-1.1,1,1,20);%Exercise 16%设夹角 t,问题转化为 minf=5/sin(t)+10/cos(t)%取 初始值pi/4,计算如下fun=(t)5/sin(t)+10/cos(t);t,f|=fminsearch(fun,pi/4)t=0.6709 f=20.8097%Exercise 17%提示:x(k+2)=f(x(k)=aA2*x(k)*(1-x(k)*(l

38、-a*x(k)*(l-x(k)%计算平衡点x%lf(x)l ex4_l8(0.9,1,20)ex4_l8(-0.9,l,20)ex4_18(l.l,l,20)ex4_ 18(-1.1,1,20)%Exercise 19 clear;close;x(l)=0;y(l)=0;for k=1:3000 x(k+1 )=l+y(k)-1.4*x(k)A2;y(k+1 )=0.3*x(k);end plot(x(1000:1500),y(1000:1500),+g);hold onplot(x(l 501:2000),y(l 501:2000),.b);plot(x(2001:2500),y(2001:

39、2500);*/);plot(x(2501:3001 ),y(2501:3001%Exercise 1x=0 4 10 12 15 22 28 34 40;y=0 13 6 8 9 5 3 0;trapz(x,y)%Exercise 2x=0 4 10 12 15 22 28 34 40;y=0 13 6 8 9 5 3 0;diff(y)./diff(x)%Exercise 3xa=-l:0.1:l;ya=0:0.1:2;x,y=meshgrid(xa,ya);z=x.*exp(-x.A2-y.A3);lpx,py=gradient(z,xa,ya);px%Exercise 4t=0:0.0

40、1:1.5;x=log(cos(t);y=cos(t)-t.*sin(t);dydx=gradient(y,x)x,id=min(abs(x-(-l);%找最接近 x=-l 的点dydx(id)%Exercise 5(2)fun=inline(,exp(2*x).*cos(x).A3);quadl(fun,0,2*pi)或用tmpzx=linspace(0,2*pi,100);y=exp(2*x).*cos(x).A3;trapz(x,y)%Exercise 5(3)fun=(x)x.*log(x.A4).*asin(l./x.A2);quadl(fun,l,3)或用trapzx=l:0.01

41、:3;y=feval(fun,x);trapz(x,y)%Exercise 5(4)fun=(x)sin(x)./x;4迎由任皿 七10,1)%注意山于下限为0,被积函数没有意义,用很小的le 10代替%Exercise 5(5)%参考 Exercise 5(4)%Exercise 5(6)fun=inline(sqrt(l+r.A2.*sin(th),r,th,);dbIquad(fun,0,1,0,2*pi)%Exercise 5(7)首先建立84页函数dblquad2clear;fun=(x,y)l+x+y.A2;clo=(x)-sqrt(2*x-x.A2);dup=(x)sqrt(2*

42、x-x.A2);dblquad2(fun,0,2,clo,dhi,100)%Exercise 6t=linspace(0,2*pi,100);x=2*cos(t);y=3*sin(t);dx=gradient(x,t);dy=gradient(y,t);f=sqil(dx.A2+dy.A2);trapz(t,f)%Exercise 7xa=-l:0.1:l;ya=0:0.1:2;x,y=meshgrid(xa,ya);z=x.*exp(x.A2+y.A2);zx,zy=gradient(z,xa,ya);f=sqil(1 +zx.八 2+zy.八 2);s=0;for i=2:length(x

43、a)for j=2:length(ya)s=s+(xa(i)-xa(i-1 )*(ya(j)-ya(j-l)*(f(ij)+f(i-lj)+f(i,j-l)+f(i-l,j-1)/4;end end s%Exercise 8 funl=inline(-(-x).A0.2.*cos(x)r);funr=inline(x.八 0.2.*cos(x);quadl(funL-1,0)+quadl(funr,0,1)%Exercise 9(以 132 为例)fun=(x)abs(sin(x);h=0.l;x=0:h:32*pi;y=feval(fun,x);tl=trapz(x,y)h=pi;x=0:h

44、:32*pi;y=feval(fun,x);t2=trapz(x,y)%步长与周期一致,结果失真q l=quad(fun,0,32*pi)q2=quadl(fun,0,32*pi)%Exercise 10(2)%先在程序编辑器,写下列函数,保存为ex50_2ffunction d=ex5_ 10_2f(fname,a,h0,e)h=h0;d=(feval(fname,a+h)-2*feval(fname,a)+feval(fname,a-h)/(h*h);d0=d+2*e;while abs(d-d0)ed0=d;h0=h;h=h0/2;d=(feval(fname,a+h)-2*feval(

45、fname,a)+feval(fname,a-h)/(h*h);end%再 在 指 令 窗 口 执 行fun=inline(x.八 2*sin(x.八 2-x-2),x);d=ex5_l0_2f(fun,1.4,0.1J e-3)%Exercise 11%提示:f 上升 时,f0;f下降 时,fv 0;f极 值,f=0.%Exercise 12在程序编辑器,写下列函数,保存为ex52ffunction I=ex5_ 12(fname,a,b,n)x=linspace(a,b,n+1);y=feval(fname,x);I=(b-a)/n/3*(y +y(n+l)+2*sum(y(3:2:n)+

46、4*sum(y(2:2:n);%再在指令窗口执行ex5_l 2(inline(l/sqrt(2*pi)*exp(-x.A2/2),),0,1,50)%Exercise 13fun=inline(,5400:isv./(8.276*v.A2+2000),v,);quadl(fun,15,30)%Exercise 14重心不超过凳边沿。1/2,2/3,3/4,.,n/(n+l)%Exercisel5利润函数 fun=inline(p-cO+k*log(M*exp(-a*p)*M*exp(a*p);p);求p使fun最大%Exercise 16clear;x=-3/4:0.01:3/4;y=(3/4

47、+x)*2.*sqrt(l-16/9.*x.A2)*9.8;P=trapz(x,y)%单位:千牛%Exercise 17clear;close;fplot(,17-tA(2/3)-5-2*tA(2/3),0,20);grid;t=fzero(17-xA(2/3)-5-2*xA(2/3)1,7)t=0:0.1:8;y=17-t.A(2/3)-5-2*t.A(2/3);trapz(t,y)-20%单位:百万元%Exercise 18%曲面面积计算%Excercise 1(1)fun=iMine(x+y?x?y);t,y=ode45(fun,0 1 2 3,1)%注意由于初值为 y(0)=l0 1

48、2 3中 0 不可缺%Excercise 1(3)%令y(l)=y,y(2)=义化为方程组%y(1 )=y(2),y(2)=0.01 *y(2)A2-2*y(1 )+sin(t)%运行下列指令clear;close;fun=(t,y)ly(2);0.01*y(2)A2-2*y(1 )+sin(t)J;t,y=ode45(fun,0 5,0;l);plot(t,y(:,l)%Excercise 1(5)%令y(l)=yM2)=y,化为方程组%y(1 )=y(2),y(2)=-mu*(y(1 )2-1 )*y(2)-y(1)%运行下列指令,注意参数m u的处理clear;close;fun=(t,

49、y,mu)y(2);-mu*(y(1 )A2-1 )*y(2)-y(1);t,y=ode45(fiin,0 20J,2;0J,l);plot(y(:,l),y(:,2);hold on;t,y=ode45(fun,0 20J,2;0J,2);plot(y(:,l),y(:,2),r);hold off;%Excercise 2roots(l 10 54 132 137 50)%通解 Al*exp(-3*t)*cos(4*t)+A2*exp(-3*t)*sin(4*t)+A3*exp(2*t)+A4*exp(-t)+A5*t*exp(t)%Excercise 3dfun=inline(T-100

50、0.25*y(l)+999.75*y(2)+0.5;999.75*y(l)-1000.25*y(2)+0.5r,x,y);fx,y=ode45(dfun,0,50,1 1 );length(x)%所用节点很多x,y=ode 15s(dfun,0,50,l;-l);length(x)%所用节点很少%Excercise 4clear;dfun=inline(x(2);2*x(3)+x(l)-(l-l/82.45)*(x(l)+l/82.45)/(sqrt(x(l)+l/82.45)A2+x(3)A2)A3-(l/82.45*(x(l)-l+l/82.45)/(sqrt(x(l)+l-l/82.45

51、)A2+x(3)A2)A3;x(4);-2*x(2)+x(3)-(1 -1/82.45)*x(3)/(sqrt(x(l)+1 /82.45)A2+x(3)A2)A3-(l/82.45*x(3)/(sqrt(x(l)+1-l/82.45)A2+x(3)A2)A37t,;x,);t,x=ode45(dfun,0 24,1,2;0;0;-1.04935371);plot(x(:/),x(:,3);%Excercise 5%方程 y=2x+yA2,y(0)=0clear;close;fun=inline(,2*x+yA2,x,y);x,y=ode45(fun,0 1.57,0);%x 的上界再增加,解

52、会“爆炸”plot(x,y)%Excercise 6clear;close;fun=(t,x,a,b)a*x4-b;t,x=ode45(fun,0 10,0.1,l,l);subplot(2,4,1 );plot(t,x)t,x=ode45(fun,0 1subplot(2,4,2);plot(t,x)t,x=ode45(fun,0 10,0.1,1,-1);subplot(2,4,3);plot(t,x)t,x=ode45(fun,0 10,-0.1,1,-1);subplot(2,4,4);plot(t,x)t,x=ode45(fun,0 10,0.1,-l,l);subplot(2,4,

53、5);plot(t,x)t,x=ode45(fun,0 10,-0.1,1,-1,1);subplot(2,4,6);plot(t,x)t,x=ode45(fun,0 10,0.1,-1,-1);subplot(2,4,7);plot(t,x)t,x=ode45(fun,0 10,-0.1subplot(2,4,8);plot(t,x)%Excercise 7%微分方程 T=k(c-T),T(0)=20dsolve(,DT=k*(c-T),T(0)=20,t,)%得 c+exp(-k*t)*(-c+20)%利用T(10)=25.2,T(20)=28.32拟合(或者解非线性方程)fun=inli

54、ne(,c(l)+exp(-c(2)*t)*(-c(l)+20),;cVt,)lsqcurvefit(fun,30 1,10 20,25.2 28.32)%解得户外温度c=33,比例系数k=0.05.%Excercise 8%微分方程 x/x=0.5*(l-x),x(0)=0.05fun=inlineC0.5*(lt,x=ode45(fun,0 10,0.05);plot(t,x)id=min(find(x0.8);t(id)%Excercise 9%微分方程组 V,(t)=K(t)*V(t)Aa,K(t)=-b*K(t)%答案 exp(20);(2)0.353;(3)30;451,0.4,9

55、.6%Chapter 7%Exercise 1syms ph th;a=sin(ph)*cos(th)-cos(ph)*sin(th)-sin(ph-th);simple(a)%化简后差的结果为0%Exercise 2syms x;s=xA4-5*xA3+5:i:xA2+5*x-6;factor(s)%Exercise 3syms a;A=l 2;2 a;iA=inv(A),v,d=eig(A)%Exercise 4syms x y;limit(3Ax+9Ax)A(l/x),x,inf)s l=limit(x*y/(sqrt(x*y+1)-1),x,0);s2=limit(s 1 ,y,0)%

56、Exercise 5syms k n x;s 1 =symsum(kA2,k,1 ,n);s 1 =simple(s 1)s2=symsum(kA(-2),k,1,inf);s2=simple(s2)s3=symsum(l/(2*n+l)/(2*x+l)A(2*n+1 ),n,0,inf);s3=simple(s3)%Exercise 6syms x y z;s=sin(xA2*y*z);s=diff(s,x,2);s=diff(s,y,l);s=subs(s,x,y,z,1,1,3)%Exercise 7syms x;s=log(x+sqrt(l+xA2);taylor(s,8,0,x)%E

57、xercise 8(以第四章习题9 为例)先用符号运算求偏导数syms x y;f=yA3/9+3*xA2*y4-9*xA2+yA24-x*y4-9;fx=diff(f,x),fy=diff(f,y)根据计算结果得方程组.求解方程组sx,sy=solve(6*x*y+l 8*x+y,l/3*yA2+3*xA2+2*y+x,x,y)得四个解(0,0),(-1/3,-6),(-7/6,-7/2),(5/6,-5/2).计算 Hesse 矩阵fh2=diff(fx,x),diff(fx,y);diff(fy,x),diff(fy,y)计算eig(subs(fh2,x,y ,0,0)得知正定,所以是极

58、小值点.极小值用subs(f,x,y,0,0)求得。同理可得(-1/3,-6)为极大值点,其它两个为鞍点。%Exercise 9(以第一小题为例)syms y;f=exp(2*y)/(exp(y)+2);fi=int(f,y)s=simple(diff(fi)-f)%Exercise 10syms x y;f=(x-y)A3*sin(x+2*y);Ix=simple(int(f,y,-x,x)%Exercise 11(3)syms x;f=x*log(xA4)*asin(l/x);Ix=int(f,x,l,3);vpa(Ix)%Exercise 12%1(3)s y m s x;s o l v

59、 e(5*xA2 3-6*xA7+8*xA6-5*xA2)%6s y m s a b;s=s o l v e(a-0.7*s i n(a)-0.2*c o s(b),b-0.7*c o s(a)+0.2*s i n(b);s.a,s.b%E x e r c i s e 1 3%1(3)d s o l v e(D 2y-0.01*D yA2+2*y=sin(t)Vy(0)=0r;Dy(0)=7,t)(解不出)%1(4)dsolve(,2*D2x-5*Dx+3*x=45*exp(2*t),;x(0)=2,;Dx(0)=r;t,)%Exercise 14%6(ii)ezplot(xA2/4+yA2/9=r)%6(vi)ezmesh(2*sin(ph)*cos(th),2*sin(ph)*sin(th),2*cos(ph),0 pi/2 0 2*piJ)

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!