1、MATLAB程序设计与应用 实验答案 第六章 刘卫国1.(1)A=randn(10,5) A = -0.4326 -0.1867 0.2944 -0.3999 -1.6041 -1.6656 0.7258 -1.3362 0.6900 0.2573 0.1253 -0.5883 0.7143 0.8156 -1.0565 0.2877 2.1832 1.6236 0.7119 1.4151 -1.1465 -0.1364 -0.6918 1.2902 -0.8051 1.1909 0.1139 0.8580 0.6686 0.5287 1.1892 1.0668 1.2540 1.1908 0
2、.2193 -0.0376 0.0593 -1.5937 -1.2025 -0.9219 0.3273 -0.0956 -1.4410 -0.0198 -2.1707 0.1746 -0.8323 0.5711 -0.1567 -0.0592 B=mean(A) B = 0.0013 0.2310 0.0253 0.3588 -0.4197 C=std(A) C = 0.9034 0.8829 1.1898 0.7832 1.0821 (2)D=max(max(A) D = 2.1832 E=min(min(A) E = -2.1707 (3)F=sum(A,2) F = -2.3288 -1
3、.3287 0.0105 6.2215 -1.4895 3.3602 4.9201 -3.6964 -3.3998 -0.3025 G=sum(sum(A) G = 1.9666 (4)H=sort(A) H = -1.6656 -0.8323 -1.5937 -1.2025 -2.1707 -1.1465 -0.5883 -1.4410 -0.3999 -1.6041 -0.4326 -0.1867 -1.3362 -0.1567 -1.0565 -0.0376 -0.1364 -0.6918 -0.0198 -0.9219 0.1253 -0.0956 0.2944 0.6686 -0.8
4、051 0.1746 0.0593 0.5711 0.6900 -0.0592 0.2877 0.1139 0.7143 0.7119 0.2193 0.3273 0.7258 0.8580 0.8156 0.2573 1.1892 1.0668 1.2540 1.1908 0.5287 1.1909 2.1832 1.6236 1.2902 1.4151 L=-sort(-A,2,descend) L = -1.6041 -0.4326 -0.3999 -0.1867 0.2944 -1.6656 -1.3362 0.2573 0.6900 0.7258 -1.0565 -0.5883 0.
5、1253 0.7143 0.8156 0.2877 0.7119 1.4151 1.6236 2.1832 -1.1465 -0.8051 -0.6918 -0.1364 1.2902 0.1139 0.5287 0.6686 0.8580 1.1909 0.2193 1.0668 1.1892 1.1908 1.2540 -1.5937 -1.2025 -0.9219 -0.0376 0.0593 -2.1707 -1.4410 -0.0956 -0.0198 0.3273 -0.8323 -0.1567 -0.0592 0.1746 0.5711 2.(1)x=0 15 30 45 60
6、75 90;y=0 0.2588 0.5000 0.7071 0.8660 0.9659 1.0000;x1=0:90;y1=interp1(x,y,x1,spline) y1 = Columns 1 through 11 0 0.0175 0.0349 0.0524 0.0698 0.0872 0.1045 0.1219 0.1392 0.1564 0.1737 Columns 12 through 22 0.1908 0.2079 0.2249 0.2419 0.2588 0.2756 0.2923 0.3090 0.3255 0.3420 0.3583 Columns 23 throug
7、h 33 0.3746 0.3907 0.4067 0.4226 0.4384 0.4540 0.4695 0.4848 0.5000 0.5150 0.5299 Columns 34 through 44 0.5446 0.5592 0.5736 0.5878 0.6018 0.6157 0.6293 0.6428 0.6561 0.6691 0.6820 Columns 45 through 55 0.6947 0.7071 0.7193 0.7313 0.7431 0.7547 0.7660 0.7771 0.7880 0.7986 0.8090 Columns 56 through 6
8、6 0.8191 0.8290 0.8387 0.8480 0.8571 0.8660 0.8746 0.8829 0.8910 0.8987 0.9062 Columns 67 through 77 0.9135 0.9204 0.9271 0.9335 0.9396 0.9454 0.9510 0.9563 0.9612 0.9659 0.9703 Columns 78 through 88 0.9744 0.9782 0.9817 0.9849 0.9878 0.9904 0.9927 0.9946 0.9963 0.9977 0.9987 Columns 89 through 91 0
9、.9995 0.9999 1.0000 x=0 15 30 45 60 75;y=0 0.2679 0.5774 1.0000 1.7320 3.7320;x1=0:75;y1=interp1(x,y,x1,spline) y1 = Columns 1 through 11 0 0.0184 0.0365 0.0545 0.0724 0.0902 0.1079 0.1255 0.1431 0.1607 0.1784 Columns 12 through 22 0.1961 0.2138 0.2317 0.2497 0.2679 0.2863 0.3048 0.3236 0.3427 0.362
10、0 0.3817 Columns 23 through 33 0.4017 0.4221 0.4429 0.4641 0.4858 0.5079 0.5305 0.5537 0.5774 0.6017 0.6266 Columns 34 through 44 0.6520 0.6780 0.7046 0.7317 0.7593 0.7876 0.8163 0.8456 0.8754 0.9058 0.9367 Columns 45 through 55 0.9681 1.0000 1.0325 1.0658 1.1003 1.1364 1.1743 1.2145 1.2572 1.3028 1
11、.3516 Columns 56 through 66 1.4041 1.4604 1.5211 1.5863 1.6565 1.7320 1.8131 1.9002 1.9936 2.0937 2.2008 Columns 67 through 76 2.3152 2.4374 2.5675 2.7060 2.8532 3.0095 3.1752 3.3506 3.5361 3.7320 x=0 15 30 45 60 75 90;y=0 0.2588 0.5000 0.7071 0.8660 0.9659 1.0000;y1=polyfit(x,y,5) y1 = 0.0000 0.000
12、0 -0.0000 0.0000 0.0174 0.0000 x=0 15 30 45 60 75;y=0 0.2679 0.5774 1.0000 1.7320 3.7320;y1=polyfit(x,y,5) y1 = 0.0000 -0.0000 0.0000 -0.0010 0.0245 0.0000 (2)x=1 4 9 16 25 36 49 64 81 100;y=1:10;x1=1:100;y1=interp1(x,y,x1,cubic) y1 = Columns 1 through 11 1.0000 1.3729 1.7125 2.0000 2.2405 2.4551 2.
13、6494 2.8292 3.0000 3.1636 3.3186 Columns 12 through 22 3.4661 3.6069 3.7422 3.8729 4.0000 4.1237 4.2435 4.3599 4.4730 4.5832 4.6907 Columns 23 through 33 4.7958 4.8988 5.0000 5.0993 5.1966 5.2921 5.3857 5.4777 5.5681 5.6570 5.7446 Columns 34 through 44 5.8309 5.9160 6.0000 6.0829 6.1647 6.2454 6.324
14、9 6.4035 6.4810 6.5577 6.6334 Columns 45 through 55 6.7082 6.7823 6.8556 6.9281 7.0000 7.0712 7.1416 7.2113 7.2804 7.3487 7.4164 Columns 56 through 66 7.4835 7.5500 7.6159 7.6812 7.7459 7.8102 7.8739 7.9372 8.0000 8.0623 8.1242 Columns 67 through 77 8.1855 8.2464 8.3068 8.3668 8.4263 8.4854 8.5441 8
15、.6024 8.6603 8.7178 8.7749 Columns 78 through 88 8.8317 8.8881 8.9442 9.0000 9.0555 9.1107 9.1655 9.2201 9.2744 9.3284 9.3821 Columns 89 through 99 9.4354 9.4884 9.5412 9.5935 9.6456 9.6973 9.7486 9.7996 9.8502 9.9005 9.9505 Column 100 10.0000 3.xi=165 123 150 123 141;yi=187 126 172 125 148;P=polyfi
16、t(xi,yi,3) P = 1.0e+003 * -0.0000 0.0013 -0.1779 8.4330 线性拟合曲线为:p(x)=1.3x2177.9x+84334.(1)P1=0,3,2;P2=5,-1,2;P3=1,0,-0.5;P=conv(P1,conv(P2,P3) P = 0 15.0000 7.0000 -3.5000 0.5000 -2.0000 -2.0000 (2)P1=0,3,2;P2=5,-1,2;P3=1,0,-0.5;P=conv(P1,conv(P2,P3);Y=roots(P) Y = 0.7071 0.1000 + 0.6245i 0.1000 - 0
17、.6245i -0.7071 -0.6667 (3)P1=0,3,2;P2=5,-1,2;P3=1,0,-0.5;P=conv(P1,conv(P2,P3);k=0:10;xi=0.2*k;Y=polyval(P,xi) Y = -2.0000 -2.3920 -2.6112 -1.7024 2.7104 15.0000 42.1120 94.1408 184.9056 332.5264 560.0000 5.(1)U,fmin=fminsearch(xiti651,1,1) U = 1.0e-004 * -0.0675 0.1715fmin = 1.9920e-010 (2)f=inline
18、(-sin(x)-cos(x.2);fminbnd(f,0,pi) ans = 0.7310 6.(1)x=pi/6 pi/4 pi/3 pi/2;f=inline(sin(x).2+cos(x).2);dx=diff(f(x,5*pi/12)/(pi/12) dx = 0 0 0 0 (2)x=1:3;f=inline(sqrt(x.2+1);dx=diff(f(x,4) dx = 0.8219 0.9262 0.9608 7.(1)g=inline(sin(x).5.*sin(5*x);I=quadl(g,0,pi) I = 0.0982 (2)g=inline(1+x.2)./(1+x.
19、4);I=quad(g,-1,1) I =2.2214 (3)g=inline(x.*sin(x)./(1+cos(x).2);I=quadl(g,0,pi) I = 2.4674 (4)f=inline(abs(cos(x+y);dblquad(f,0,pi,0,pi) ans = 6.2832 9.(1)矩阵求逆法:A=2,3,5;3,7,4;1,-7,1;b=10;3;5;x=inv(A)*b x = -1.8060 -0.5373 3.0448 矩阵除法:A=2,3,5;3,7,4;1,-7,1;b=10;3;5;x=Ab x = -1.8060 -0.5373 3.0448 矩阵分解
20、法:A=2,3,5;3,7,4;1,-7,1;b=10;3;5;Q,R=qr(A);x=R(Qb) x = -1.8060 -0.5373 3.0448 (2)矩阵求逆法:A=5,1,-1,0;1,0,3,-1;-1,-1,0,5;0,0,2,4;b=1;2;3;-1;x=inv(A)*b x = 1.4000 -5.9000 0.1000 -0.3000 矩阵除法:A=5,1,-1,0;1,0,3,-1;-1,-1,0,5;0,0,2,4;b=1;2;3;-1;x=Ab x = 1.4000 -5.9000 0.1000 -0.3000 矩阵分解法:A=5,1,-1,0;1,0,3,-1;-
21、1,-1,0,5;0,0,2,4;b=1;2;3;-1;Q,R=qr(A);x=R(Qb) x = 1.4000 -5.9000 0.1000 -0.3000 10.A=2 1 -1 1;4 2 -2 1;2 1 -1 -1;b=1;2;1;x,y=line_solution(A,b) 原方程组有无穷个解,特解为x,齐次方程组的基础解系为yWarning: Rank deficient, rank = 2, tol = 4.3512e-015. In line_solution at 11方程组无解x = y = -0.5000 0.5000 1.0000 0 0 1.0000 0 0 11.
22、(1)f=inline(x-sin(x)./x);x=fzero(f,0.5) x = 0.8767 (2)f=inline(sin(x).2).*exp(-0.1.*x)-0.5.*abs(x);x=fzero(f,1.5) x = 1.6738 12.x=fsolve(xiti612,0.5,0.5,optimset(Display,off) x = 0.5000y = 0.5000f = -0.0509f = -0.0509 0.1173x = 0.5000y = 0.5000f = -0.0509f = -0.0509 0.1173x = 0.5000y = 0.5000f = -0.
23、0509f = -0.0509 0.1173x = 0.6459y = 0.3739f = 0.0055f = 0.0055 0.0044x = 0.6459y = 0.3739f = 0.0055f = 0.0055 0.0044x = 0.6459y = 0.3739f = 0.0055f = 0.0055 0.0044x = 0.6355y = 0.3734f = 1.9417e-005f = 1.0e-004 * 0.1942 0.2589x = 0.6355y = 0.3734f = 1.9425e-005f = 1.0e-004 * 0.1942 0.2589x = 0.6355y
24、 = 0.3734f = 1.9419e-005f = 1.0e-004 * 0.1942 0.2591x = 0.6354y = 0.3734f = 2.3754e-010f = 1.0e-009 * 0.2375 0.2957x = 0.6354y = 0.3734f = 7.9432e-009f = 1.0e-008 * 0.7943 0.5602x = 0.6354y = 0.3734f = 1.8684e-009f = 1.0e-007 * 0.0187 0.1936x =0.6354 0.3734 13.x0=0;xf=20;y1=0;x,y=ode45(xiti6131,x0,x
25、f,y1) x = 0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000 3.5000 4.0000 4.5000 5.0000 5.5000 6.0000 6.5000 7.0000 7.5000 8.0000 8.5000 9.0000 9.5000 10.0000 10.5000 11.0000 11.5000 12.0000 12.5000 13.0000 13.5000 14.0000 14.5000 15.0000 15.5000 16.0000 16.5000 17.0000 17.5000 18.0000 18.5000 19.0000 19.
26、5000 20.0000y = 0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN (2)x0=0;xf=20;x,y=ode45(xiti6132,x0,xf,-3,2) x,y 此题结果过长,疑似错误或不会做。14.f=(t,x)-8/3*x(1)+x(2)*x(3);-10*x(2)+10*x(3);-x(1)*x(2)
27、+28*x(2)-x(3);t_f=100;x0=0;0;1e-10;t,x=ode45(f,0,t_f,x0)figure(2);plot3(x(:,1),x(:,2),x(:,3);axis(10 40 -20 20 -20 20) t = 0 0.1250 0.2500 0.3750 0.5000 0.5352 0.5705 0.6057 0.6409 0.6761 0.7114 0.7466 0.7818 0.8308 0.8797 0.9286 0.9776 1.0105 1.0434 1.0763 1.1092 1.1421 1.1750 1.2079 1.2409 1.2797
28、1.3186 1.3575 1.3964 1.4246 1.4528 1.4810 1.5092 1.5374 1.5656 1.5938 1.6220 1.6479 1.6737 1.6996 1.7255 1.7506 1.7757 1.8008 1.8259 1.8507 1.8755 1.9004 1.9252 1.9495 1.9739 1.9982 2.0225 2.0467 2.0709 2.0950 2.1192 2.1432 2.1672 2.1912 2.2152 2.2384 2.2616 2.2848 2.3081 2.3201 2.3321 2.3442 2.3562 2.3682 2.3803 2.3923 2.4044 2.4154 2.4265 2.4376 2.4487 2.4585 2.4684 2.4783 2.4882 2.4976 2.5069 2.5163 2.5257 2.5420
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1