楼顺天--第二版--matlab7.x-程序设计语言答案(共29页).doc
《楼顺天--第二版--matlab7.x-程序设计语言答案(共29页).doc》由会员分享,可在线阅读,更多相关《楼顺天--第二版--matlab7.x-程序设计语言答案(共29页).doc(29页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上P83No.3 A=5-round(100*rand(50,2)/10A = 0.8000 -4.2000 4.1000 5.0000 -1.0000 0.4000 0.3000 0.8000 -2.0000 0.4000 -2.0000 -2.7000 -1.4000 1.8000 4.7000 -2.8000 4.3000 0.3000 1.8000 4.6000 -0.3000 3.2000 -1.5000 -2.2000 0.9000 0.3000 -3.2000 3.5000 -2.2000 1.6000 -4.7000 -1.1000 -0.3000 3.
2、1000 1.7000 -2.4000 3.9000 2.6000 -1.1000 -4.2000 -2.8000 2.3000 0.8000 -2.7000 4.1000 3.1000 2.3000 2.1000 3.5000 4.1000 2.2000 -0.8000 0.6000 -1.8000 -0.3000 -0.5000 0.4000 0.7000 -3.8000 -1.4000 -0.2000 -1.5000 -4.4000 -1.8000 -1.4000 -1.4000 -4.6000 -4.5000 2.6000 2.9000 -1.8000 -2.1000 2.1000 2
3、.6000 -1.7000 3.8000 -2.0000 -1.1000 4.3000 0.5000 2.5000 0.4000 2.8000 -1.6000 -1.7000 -2.7000 -3.4000 1.5000 1.6000 -1.6000 -2.8000 0.8000 -1.8000 -3.4000 4.9000 -3.3000 -1.0000 2.40001.1000 -1.1000No.6 A=randn(10,10)A = -0.4326 -0.1867 0.2944 -0.3999 -1.6041 -1.0106 0.0000 0.5689 0.6232 0.3899 -1
4、.6656 0.7258 -1.3362 0.6900 0.2573 0.6145 -0.3179 -0.2556 0.7990 0.0880 0.1253 -0.5883 0.7143 0.8156 -1.0565 0.5077 1.0950 -0.3775 0.9409 -0.6355 0.2877 2.1832 1.6236 0.7119 1.4151 1.6924 -1.8740 -0.2959 -0.9921 -0.5596 -1.1465 -0.1364 -0.6918 1.2902 -0.8051 0.5913 0.4282 -1.4751 0.2120 0.4437 1.190
5、9 0.1139 0.8580 0.6686 0.5287 -0.6436 0.8956 -0.2340 0.2379 -0.9499 1.1892 1.0668 1.2540 1.1908 0.2193 0.3803 0.7310 0.1184 -1.0078 0.7812 -0.0376 0.0593 -1.5937 -1.2025 -0.9219 -1.0091 0.5779 0.3148 -0.7420 0.5690 0.3273 -0.0956 -1.4410 -0.0198 -2.1707 -0.0195 0.0403 1.4435 1.0823 -0.8217 0.1746 -0
6、.8323 0.5711 -0.1567 -0.0592 -0.0482 0.6771 -0.3510 -0.1315 -0.2656 i,j=find(-0.5A length(j)ans = 26P146No.5clear;x=-3:0.1:3;figure(1)y1=2*x+5;y2=x.2-3*x+1;subplot(1,2,1),plot(x,y1),title(函数1)axis(-3 3 -5 5)subplot(1,2,2),plot(x,y2),title(函数2)axis(-3 3 -5 5)No.7clear;x=190 33 45 42 45;h=pie(x,生活费,资料
7、费,电话费,购买衣服,其他费用)explode=0 1 0 0 0;figure(1)pie(x,生活费,资料费,电话费,购买衣服,其他费用)title(每月消费比例)h = 175.0033 176.0023 177.0022 178.0022 179.0022 180.0022 181.0022 182.0022 183.0022 184.0022No.9x,y=meshgrid(-2:0.25:2); z=x.2+y.2+sin(x*y); contour3(x,y,z,30)surface(x,y,z,EdgeColor,.8 .8 .8,FaceColor,none) grid of
8、f view(-15,25)P184No.1clear;function t=sushu(n)n=input(输入的数是)A=sqrt(n);k=floor(A);for i=2:kif mod(n,i)=0 t=0; break;else t=1;endendNo.3zeros_num_all = 0;for i=1:2006 zeros_num = zeroscnt1(i); %zeros_num = zeroscnt2(i); zeros_num_all = zeros_num + zeros_num_all;enddisp(12006中“0”的个数为:,num2str(zeros_nu
9、m_all)zeroscnt1函数:function num = zeroscnt1(data)data_str = num2str(data);num_vec = find(data_str = 0);num = length(num_vec);zeroscnt2函数function num = zeroscnt2(data)num = 0;while(data=1) if mod(data,10) = 0 num = num + 1; data = fix(data/10); else data = fix(data/10); endendNo.5i=0;for x=-3:0.01:3 i
10、=i+1; X(i)=x; if and(x=-3,x=-1,x1) Y(i)=-x*x+1; else Y(i)=(-x*x+4*x-3)/2; endendplot(X,Y)No.8clear;I=input(个人完成的利润为)if I10&I20&I40 y=10*0.17+(I-40)*0.01 end m02个人完成的利润为25I = 25y = 1.6000No.9clear;i=1;s=0;a1=1;a2=1;while i ss = 24.5701P263No.1(1) a=1 9 8;7 2 5;3 -2 7a = 1 9 8 7 2 5 3 -2 7 det(a)ans =
11、 -442 inv(a)ans = -0.0543 0.1787 -0.0656 0.0769 0.0385 -0.1154 0.0452 -0.0656 0.1380(2) b=1 0 -7 5;0 -26 7 2;7 4 3 5;8 -3 2 15b = 1 0 -7 5 0 -26 7 2 7 4 3 5 8 -3 2 15 det(b)ans = -9334 inv(b)ans = 0.1501 0.0654 0.3046 -0.1603 -0.0509 -0.0471 -0.0312 0.0336 -0.1697 -0.0204 -0.0703 0.0827 -0.0676 -0.0
12、416 -0.1593 0.1478No.22,(1) a1=1 2 3;2 2 5;3 5 1; b1=11;12;31;x1=inv(a1)*b1x1 = 1.8000 5.2000 -0.4000(2)a2=3 1 0 5;0 6 7 3;0 4 3 0;2 -1 2 6;b2=2;4;7;8; x2=inv(a2)*b2x2 = 28.1892 -9.4595 14.9459 -14.6216No.3clear;t=1:1:10;t=t;y=4.842,4.362,3.754,3.368,3.169,3.083,3.304,3.016,3.012,3.005;x1=ones(size(
13、t),exp(-t);x2=ones(size(t),t.*exp(-t);p1=x1y;p2=x2y;tt=linspace(1,10,1000);plot(t,y,*,tt,p1(1)+p1(2)*exp(-tt),r-,tt,p2(1)+p2(2)*tt.*exp(-tt),c-)grid on,legend(给定数据,y1拟合,y2拟合)No.7clear;t=1:10;tt=1:0.01:10;y=15,39.5,66,85.5,89,67.5,12,-86.4,-236.9,-448.4;p1=polyfit(t,y,2);y1=polyval(p1,tt);p2=polyfit(
14、t,y,3);y2=polyval(p2,tt);plot(t,y,b*,tt,y1,r-,tt,y2,c-);legend(样本点,二次拟合,三次拟合),grid onNo.8p1,p2,p3,p4p1 = 1 -2 -3 4 2p2 = 1 -7 5 31 -30p3 = 1 -1 -25 25p4 = -2 3 1 5 8 0 roots(p1),roots(p2),roots(p3),roots(p4)ans = 2.4142 1.4142 -1.4142 -0.4142ans = 5.0000 -2.0000 3.0000 1.0000ans = -5.0000 5.0000 1.0
15、000ans = 0 2.4176 0.0148 + 1.3215i 0.0148 - 1.3215i -0.9473 No.9y11=polyval(p1,-1.5),y12=polyval(p1,2.1),y13=polyval(p1,3.5)y11 = 1.0625y12 = -1.9039y13 = 43.5625 y21=polyval(p2,-1.5),y22=polyval(p2,2.1),y23=polyval(p2,3.5)y21 = -36.5625y22 = 11.7711y23 = -10.3125 y31=polyval(p3,-1.5),y32=polyval(p3
16、,2.1),y33=polyval(p3,3.5)y31 = 56.8750y32 = -22.6490y33 = -31.8750 y41=polyval(p4,-1.5),y42=polyval(p4,2.1),y43=polyval(p4,3.5)y41 = 26.2500y42 = 24.7733y43 = -468.1250 13, 15,16,20No.13 a=rand(1,50);amax=max(a)amin=min(a)ua=mean(a)vara=(std(a)2b=randn(1,50);bmax=max(a)bmin=min(a)ub=mean(a)varb=(std
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 楼顺天 第二 matlab7 程序设计语言 答案 29
限制150内