1、matlab数学实验课后答案大学课程%Page20,ex1(5) 等于exp(1),exp(2);exp(3),exp(4)(7) 3=1*3, 8=2*4(8) a为各列最小值,b为最小值所在的行号(10) 1=4,false, 2=3,false, 3=2, ture, 4=1,ture(11) 答案表明:编址第2元素满足不等式(30=20)和编址第4元素满足不等式(40=10)(12) 答案表明:编址第2行第1列元素满足不等式(30=20)和编址第2行第2列元素满足不等式(40=10)%Page20, ex2(1)a, b, c的值尽管都是1, 但数据类型分别为数值,字符, 逻辑, 注意
2、a与c相等, 但他们不等于b(2)double(fun)输出的分别是字符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.4-2.x; fmin,min_index=min(f)fmin = -1.3907 %最小值min_index = 54 %最小值点编址 x(min_index)ans = 0.6500 %最小值点 f1,x1_index=min(abs(f) %求近似根-绝对值最小的点f1 = 0.0328x1_inde
3、x = 24 x(x1_index)ans = -0.8500 x(x1_index)=;f=x.4-2.x; %删去绝对值最小的点以求函数绝对值次小的点 f2,x2_index=min(abs(f) %求另一近似根-函数绝对值次小的点f2 = 0.0630x2_index = 65 x(x2_index)ans = 1.2500%Page20,ex5 z=magic(10)z = 92 99 1 8 15 67 74 51 58 40 98 80 7 14 16 73 55 57 64 41 4 81 88 20 22 54 56 63 70 47 85 87 19 21 3 60 62 6
4、9 71 28 86 93 25 2 9 61 68 75 52 34 17 24 76 83 90 42 49 26 33 65 23 5 82 89 91 48 30 32 39 66 79 6 13 95 97 29 31 38 45 72 10 12 94 96 78 35 37 44 46 53 11 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.1577 46.1880 46.765
5、4 50.2295 53.6936 13.8564 2.8868 3.4641 6.9282 10.3923 z(8,:)=z(8,:)+z(3,:)z = 92 99 1 8 15 67 74 51 58 40 98 80 7 14 16 73 55 57 64 41 4 81 88 20 22 54 56 63 70 47 85 87 19 21 3 60 62 69 71 28 86 93 25 2 9 61 68 75 52 34 17 24 76 83 90 42 49 26 33 65 23 5 82 89 91 48 30 32 39 66 83 87 101 115 119 8
6、3 87 101 115 119 10 12 94 96 78 35 37 44 46 53 11 18 100 77 84 36 43 50 27 59%Page 40 ex1先在编辑器窗口写下列M函数,保存为eg2_1.mfunction xbar,s=ex2_1(x)n=length(x);xbar=sum(x)/n;s=sqrt(sum(x.2)-n*xbar2)/(n-1);例如x=81 70 65 51 76 66 90 87 61 77;xbar,s=ex2_1(x)xbar = 72.4000s = 12.1124%Page 40 ex2s=log(1);n=0;while s
7、e k=k+1;F(k)=F(k-1)+F(k-2); x=F(k)/F(k-1);end a,x,k 计算至k=21可满足精度%Page 40 ex4clear;tic;s=0;for i=1: s=s+sqrt(3)/2i;ends,toctic;s=0;i=1;while i1.1)+x.*(x=-1.1)-1.1*(x1);p=p+b*exp(-y.2-6*x.2).*(x+y-1).*(x+y=1);p=p+a*exp(-0.75*y.2-3.75*x.2+1.5*x).*(x+y A=1 2 3;4 5 6;7 8 0;C=2 -5 -22;-5 -24 -56;-22 -56 -
8、16; X=lyap(A,C)X = 1.0000 -1.0000 -0.0000 -1.0000 2.0000 1.0000 -0.0000 1.0000 7.0000%Chapter 3%Exercise 1 a=1,2,3;b=2,4,3;a./b,a.b,a/b,abans = 0.5000 0.5000 1.0000ans = 2 2 1ans = 0.6552 %一元方程组x2,4,3=1,2,3的近似解ans = 0 0 0 0 0 0 0.6667 1.3333 1.0000%矩阵方程1,2,3x11,x12,x13;x21,x22,x23;x31,x32,x33=2,4,3的
9、特解%Exercise 2(1) A=4 1 -1;3 2 -6;1 -5 3;b=9;-2;1; rank(A), rank(A,b) %A,b为增广矩阵ans = 3ans = 3 %可见方程组唯一解 x=Abx = 2.3830 1.4894 2.0213%Exercise 2(2) A=4 -3 3;3 2 -6;1 -5 3;b=-1;-2;1; rank(A), rank(A,b)ans = 3ans = 3 %可见方程组唯一解 x=Abx = -0.4706 -0.2941 0%Exercise 2(3) A=4 1;3 2;1 -5;b=1;1;1; rank(A), rank
10、(A,b)ans = 2ans = 3 %可见方程组无解 x=Abx = 0.3311 -0.1219 %最小二乘近似解%Exercise 2(4) a=2,1,-1,1;1,2,1,-1;1,1,2,1;b=1 2 3;%注意b的写法 rank(a),rank(a,b)ans = 3ans = 3 %rank(a)=rank(a,b) abans = 1 0 1 0 %一个特解%Exercise 3 a=2,1,-1,1;1,2,1,-1;1,1,2,1;b=1,2,3; x=null(a),x0=abx = -0.6255 0.6255 -0.2085 0.4170x0 = 1 0 1 0
11、%通解kx+x0另一种解法 rref(a,b)ans = 1.0000 0 0 1.5000 1.0000 0 1.0000 0 -1.5000 0 0 0 1.0000 0.5000 1.0000%通解k1.5,-1.5,0.5,1+1,0,1,0%Exercise 4%一年后城市=上年城市99%+上年农村5%;一年后农村=上年城市1%+上年农村95% x0=0.2 0.8;a=0.99 0.05;0.01 0.95; x1=a*x, x2=a2*x, x10=a10*x x=x0;for i=1:1000,x=a*x;end,xx = 0.8333 0.1667 x0=0.7 0.3; x
12、=x0;for i=1:1000,x=a*x;end,xx = 0.8333 0.1667 %注意结果不受x0改变的影响 v,e=eig(a)v = 0.9806 -0.7071 0.1961 0.7071e = 1.0000 0 0 0.9400 v(:,1)./xans = 1.1767 1.1767 %v(:,1)与x成比例,说明x是最大特征值对应的特征向量%Exercise 5%用到公式(3.11)(3.12) B=6,2,1;2.25,1,0.2;3,0.2,1.8;x=25 5 20; C=B/diag(x)C = 0.2400 0.4000 0.0500 0.0900 0.200
13、0 0.0100 0.1200 0.0400 0.0900 A=eye(3,3)-CA = 0.7600 -0.4000 -0.0500 -0.0900 0.8000 -0.0100 -0.1200 -0.0400 0.9100 D=17 17 17;x=ADx = 37.5696 25.7862 24.7690%Exercise 6(1) a=4 1 -1;3 2 -6;1 -5 3;det(a),inv(a),v,d=eig(a)ans = -94ans = 0.2553 -0.0213 0.0426 0.1596 -0.1383 -0.2234 0.1809 -0.2234 -0.053
14、2v = 0.0185 -0.9009 -0.3066 -0.7693 -0.1240 -0.7248 -0.6386 -0.4158 0.6170d = -3.0527 0 0 0 3.6760 0 0 0 8.3766%Exercise 6(2) a=1 1 -1;0 2 -1;-1 2 0;det(a),inv(a),v,d=eig(a)ans = 1ans = 2.0000 -2.0000 1.0000 1.0000 -1.0000 1.0000 2.0000 -3.0000 2.0000v = -0.5773 0.5774 + 0.0000i 0.5774 - 0.0000i -0.
15、5773 0.5774 0.5774 -0.5774 0.5773 - 0.0000i 0.5773 + 0.0000id = 1.0000 0 0 0 1.0000 + 0.0000i 0 0 0 1.0000 - 0.0000i%Exercise 6(3) A=5 7 6 5;7 10 8 7;6 8 10 9;5 7 9 10A = 5 7 6 5 7 10 8 7 6 8 10 9 5 7 9 10 det(A),inv(A), v,d=eig(A)ans = 1ans = 68.0000 -41.0000 -17.0000 10.0000 -41.0000 25.0000 10.00
16、00 -6.0000 -17.0000 10.0000 5.0000 -3.0000 10.0000 -6.0000 -3.0000 2.0000v = 0.8304 0.0933 0.3963 0.3803 -0.5016 -0.3017 0.6149 0.5286 -0.2086 0.7603 -0.2716 0.5520 0.1237 -0.5676 -0.6254 0.5209d = 0.0102 0 0 0 0 0.8431 0 0 0 0 3.8581 0 0 0 0 30.2887%Exercise 6(4)(以n=5为例,n=其他值类似) %关键是矩阵的定义,当n很大时不能直接
17、写出。%方法一(三个for)n=5;for i=1:n, a(i,i)=5;endfor i=1:(n-1),a(i,i+1)=6;endfor i=1:(n-1),a(i+1,i)=1;enda%方法二(一个for)n=5;a=zeros(n,n);a(1,1:2)=5 6;for i=2:(n-1),a(i,i-1,i,i+1)=1 5 6;enda(n,n-1 n)=1 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-1,1),b;zeros(1,n)+zer
18、os(1,n);c,zeros(n-1,1)%下列计算 det(a)ans = 665 inv(a)ans = 0.3173 -0.5865 1.0286 -1.6241 1.9489 -0.0977 0.4887 -0.8571 1.3534 -1.6241 0.0286 -0.1429 0.5429 -0.8571 1.0286 -0.0075 0.0376 -0.1429 0.4887 -0.5865 0.0015 -0.0075 0.0286 -0.0977 0.3173 v,d=eig(a)v = -0.7843 -0.7843 -0.9237 0.9860 -0.9237 0.55
19、46 -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.0257 0.0274 0.0257d = 0.7574 0 0 0 0 0 9.2426 0 0 0 0 0 7.4495 0 0 0 0 0 5.0000 0 0 0 0 0 2.5505%Exercise 7(1) a=4 1 -1;3 2 -6;1 -5 3;v,d=eig(a)v = 0.0185 -0.9009 -0.3066 -
20、0.7693 -0.1240 -0.7248 -0.6386 -0.4158 0.6170d = -3.0527 0 0 0 3.6760 0 0 0 8.3766 det(v)ans = -0.9255 %v行列式正常, 特征向量线性相关,可对角化 inv(v)*a*v %验算ans = -3.0527 0.0000 -0.0000 0.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 -
21、0.2607 0.4213 %用jordan特征向量不同d2 = 8.3766 0 0 0 -3.0527 - 0.0000i 0 0 0 3.6760 + 0.0000i v2a*v2ans = 8.3766 0 0.0000 0.0000 -3.0527 0.0000 0.0000 0.0000 3.6760 v(:,1)./v2(:,2) %对应相同特征值的特征向量成比例,说明两种方法结果本质上相同ans = 2.4491 2.4491 2.4491%Exercise 7(2) a=1 1 -1;0 2 -1;-1 2 0;v,d=eig(a)v = -0.5773 0.5774 + 0
22、.0000i 0.5774 - 0.0000i -0.5773 0.5774 0.5774 -0.5774 0.5773 - 0.0000i 0.5773 + 0.0000id = 1.0000 0 0 0 1.0000 + 0.0000i 0 0 0 1.0000 - 0.0000i det(v)ans = -5.0566e-028 -5.1918e-017i %v的行列式接近0, 特征向量线性相关,不可对角化 v,d=jordan(a)v = 1 0 1 1 0 0 1 -1 0d = 1 1 0 0 1 1 0 0 1 %jordan标准形不是对角的,所以不可对角化%Exercise 7
23、(3) A=5 7 6 5;7 10 8 7;6 8 10 9;5 7 9 10A = 5 7 6 5 7 10 8 7 6 8 10 9 5 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.5520 0.1237 -0.5676 -0.6254 0.5209d = 0.0102 0 0 0 0 0.8431 0 0 0 0 3.8581 0 0 0 0 30.2887 inv(v)*A*vans = 0.0102 0.0000 -0.
24、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不行, 原因未知%Exercise 7(4)参考6(4)和7(1), 略%Exercise 8 只有(3)对称且特征值全部大于零, 所以只有(3)是正定矩阵.%Exercise 9 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(1:3,:)ans = 2 rank(a(1 2 4,:) %1,2,4行为最大无关组ans = 3 b=a(1 2 4,:);c=a(3 5,:); bc %线性表示的系数ans = 0.5000 5.0000 -0.5000 1.0000 0 -5.0000%Exercise 10 a=
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1