数学实验报告(共19页).docx
精选优质文档-倾情为你奉上数学实验报 告 信息 16 翟羿、朱一明实 验 目 录第二次实验1.题目:某车间有甲,乙,丙三台车床可用于加工三种零件,这三台车床可用于工作的最多时间分别为700,800和900,需要加工的三种零件的数量分别为300,400和500.不同车床加工不同的零件所用时间和费用如表所示,在完成任务的前提下,如何分配加工任务才能使加工费最少? 工时数分配表车床 加工单位零件所需时数 加工单位零件所需费用 可用于工 名称零件1零件2零件3零件1零件2零件3 作的时数 甲0.60.50.5788700 乙0.40.70.5878800 丙0.80.60.67989002.分析问题: 此题考察用Matlab软件求线性规划问题。这是一个优约束的优化问题,其模型包括:甲生产零件1,零件2,零件3的个数分别为x1,x2,x3;以乙生产零件1,零件2,零件3的个数分别为x4,x5,x6;丙生产零件1,零件2,零件3的个数分别为x7,x8,x9. 目标函数为:W=7x1+8x2+8x3+8x4+7x5+8x6+7x7+9x8+8x9约束条件为: X1+x4+x7=300X2+x5+x8=400X3+x6+x9=5000.6x1+0.5x2+0.5x3<=7000.4x4+0.7x5+0.5x6<=8000.8x7+0.6x8+0.6x9<=900以及非负性约束x1,x2,x3,x4,x5,x6,x7,x8,x9都大于等于零。3.建立模型:Min W=7x1+8x2+8x3+8x4+7x5+8x6+7x7+9x8+8x9;X1+x4+x7=300X2+x5+x8=400X3+x6+x9=5000.6x1+0.5x2+0.5x37000.4x4+0.7x5+0.5x68000.8x7+0.6x8+0.6x9900X1,x2,x3,x4,x5,x6,x7,x8,x904.编写程序: c=7,8,8,8,7,8,7,9,8 A=0.6,0.5,0.5,0,0,0,0,0,0;0,0,0,0.4,0.7,0.5,0,0,0;0,0,0,0,0,0,0.8,0.6,0.6, b=700;800;900 aeq=1,0,0,1,0,0,1,0,0;0,1,0,0,1,0,0,1,0;0,0,1,0,0,1,0,0,1 beq=300;400;500 vlb=0,0,0,0,0,0,0,0,0 vub= x,minz=linprog(c,A,b,aeq,beq,vlb,vub)5.运行结果: c = 7 8 8 8 7 8 7 9 8A = 0.6000 0.5000 0.5000 0 0 0 0 0 0 0 0 0 0.4000 0.7000 0.5000 0 0 0 0 0 0 0 0 0 0.8000 0.6000 0.6000b = 700 800 900aeq = 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1beq = 300 400 500vlb = 0 0 0 0 0 0 0 0 0vub = Optimization terminated successfully.x = 103.7917 0.0000 149.9740 0.0000 400.0000 151.1015 196.2083 0.0000 198.9245minz = 8.9000e+0036.结果分析: 由于此实际问题的结果必为整数,所以对于软件得出的结果还需进一步优化。即需将结果取整数,再进一步确定最优解,即软件本身存在一些缺陷。 题目2,设有三种证券S1,S2,S3,期望收益率分别为10%,15%和40%,风险分别为10%,5%和20%。假定投资总风险用最大一种投资股票的风险来度量,且同期银行存款利率为=5%,无风险,为投资者建议一种投资策略(投资比例),使其尽可能获得最大收益。1问题分析:条件假设:假设投资三种证券S1,S12,S3和银行存储资金分别为x1,x2,x3,x4.总投资金额为M.并设这几种之间是相互独立的,且在投资的同一时期内收益率与风险都为定值,不受意外因素的影响。2建立模型:设三种证券的风险为qi,投资三种证券的风险度分别为qi*Xi/M,i=1,2,3,为使投资者获得最大的收益,可建立如下模型: Maxri*Xi(i=1,4) X1+X2+X3+X4=M Xi0,i=1,2,3,4.3编写程序:a=0;while(1.1-a)>1 c=-0.1,-0.15,-0.4,-0.05; aeq=1,1,1,1; beq=1; A=0.1,0,0,0;0,0.05,0,0;0,0,0.2,0; b=a;a;a; vlb=0,0,0,0; vub=; x,val=linprog(c,A,b,aeq,beq,vlb,vub); a %风险度 x=x' Q=-val %风险度a对应的收益率 plot(a,Q,'.') axis(0,0.1,0,0.5) hold on a=a+0.001;endxlabel('a'),ylabel('Q')4运行结果: 图:风险与收益题目3:某单位有300万元可用于投资,共有6个项目可供选择,其投资额分别为40,60,80,50,90,70(万元),预计三年可获利润分别为10,12,15,11,16,13(万元),试确定一种投资客使得三年获得的利润最大。程序设计:依题意可建立以下模型:fz=10,12,15,11,16,13tj=40,60,80,50,90,70;k=1;for g1=0:1 for g2=0:1 for g3=0:1 for g4=0:1 for g5=0:1 for g6=0:1 fa=g1,g2,g3,g4,g5,g6; if tj*fa'<=300 fajz(k,1:6)=fa; k=k+1 end end end end end endendfalr=fajz*jz'f,i=max(falr)zjfa=fajz(i,1:6)fatz=tj*zjfa'程序运行结果为zjfa = 1 1 1 1 0 1fatz = 300f = 61即可获得的最大利润为60万。题目4表9-1给出三只股票49个周末的收盘价,周数A股B股C股周数A股B股C股110.30.7710.62611.81.214.7210.60.8111.22712.21.2414.9310.80.8911.92812.41.3215.6410.70.9311.72912.41.3215.5510.80.9011.63012.71.2915.8610.80.9311.03112.51.3215.4711.21.1012.13212.31.3214.9811.30.9613.23312.61.3315.3911112.63412.41.3715.61010.91.0412.63512.61.4814.21110.61.0412.63612.11.4913.81210.91.0912.63711.91.51141311.51.112.73811.91.3213.81411.51.2613.63912.41.3214.21511.81.1714.24012.11.313.81612.21.0614.741121.281417121.1314.44212.41.1714.31812.11.0914.343121.1413.61912.31.031544121.0814.12012.11.0814.945121.0914.42111.41.0813.44612.11.0714.62211.91.121447121.214.42311.91.121448121.2414.424121.1514.74912.11.2614.52511.81.214.3(1)、分别计算这三只股票的周收益率的时间序列,平均收益率和他们收益率分布的方差协方差矩阵;(2)、允许卖空的情况下给出这三只股票风险最小的投资策略。(1)程序设计:a(1,:)=10.3,10.6,10.8,10.7,10.8,10.8,11.2,11.3,11,10.9,10.6,10.9,11.5,11.5,11.8,12.2,12,12.1,12.3,12.1,11.4,11.9,11.9,12,11.8,11.8,12.2,12.4,12.4,12.7,12.5,12.3,12.6,12.4,12.6,12.1,11.9,11.9,12.4,12.1,12,12.4,12,12,12,12.1,12,12,12.1;a(2,:)=0.77,0.81,0.89,0.93,0.90,0.93,1.10,0.96,1,1.04,1.04,1.09,1.1,1.26,1.17,1.06,1.13,1.09,1.03,1.08,1.08,1.12,1.12,1.15,1.2,1.2,1.24,1.32,1.32,1.29,1.32,1.32,1.33,1.37,1.48,1.49,1.51,1.32,1.32,1.3,1.28,1.17,1.14,1.08,1.09,1.07,1.2,1.24,1.26;a(3,:)=10.6,11.2,11.9,11.7,11.6,11,12.1,13.2,12.6,12.6,12.6,12.6,12.7,13.6,14.2,14.7,14.4,14.3,15,14.9,13.4,14,14.4,14.7,14.3,14.7,14.9,15.6,15.5,15.8,15.4,14.9,15.3,15.6,14.2,13.8,14,13.8,14.2,13.8,14,14.3,13.6,14.1,14.4,14.6,14.4,14.4,14.5; for i=1:3 for j=2:49 b(i,j)=(a(i,j)-a(i,j-1)/a(i,j-1); endendb运行结果:b = Columns 1 through 16 0 0.0291 0.0189 -0.0093 0.0093 0 0.0370 0.0089 -0.0265 -0.0091 -0.0275 0.0283 0.0550 0 0.0261 0.0339 0 0.0519 0.0988 0.0449 -0.0323 0.0333 0.1828 -0.1273 0.0417 0.0400 0 0.0481 0.0092 0.1455 -0.0714 -0.0940 0 0.0566 0.0625 -0.0168 -0.0085 -0.0517 0.1000 0.0909 -0.0455 0 0 0 0.0079 0.0709 0.0441 0.0352 Columns 17 through 32 -0.0164 0.0083 0.0165 -0.0163 -0.0579 0.0439 0 0.0084 -0.0167 0 0.0339 0.0164 0 0.0242 -0.0157 -0.0160 0.0660 -0.0354 -0.0550 0.0485 0 0.0370 0 0.0268 0.0435 0 0.0333 0.0645 0 -0.0227 0.0233 0 -0.0204 -0.0069 0.0490 -0.0067 -0.1007 0.0448 0.0286 0.0208 -0.0272 0.0280 0.0136 0.0470 -0.0064 0.0194 -0.0253 -0.0325 Columns 33 through 48 0.0244 -0.0159 0.0161 -0.0397 -0.0165 0 0.0420 -0.0242 -0.0083 0.0333 -0.0323 0 0 0.0083 -0.0083 0 0.0076 0.0301 0.0803 0.0068 0.0134 -0.1258 0 -0.0152 -0.0154 -0.0859 -0.0256 -0.0526 0.0093 -0.0183 0.1215 0.0333 0.0268 0.0196 -0.0897 -0.0282 0.0145 -0.0143 0.0290 -0.0282 0.0145 0.0214 -0.0490 0.0368 0.0213 0.0139 -0.0137 0 Column 49 0.0083 0.0161 0.0069 第三次实验题目1:请按照上述公式分别编程计算,并与就精度与叠加次数进行比较,能得出怎样的结论?解: sa=0;sb=0;sc=0;sd=0;sx=0;n=1000;digits(22)for k=1:n sa=sa+1/(2*k-1)2; sb=sb+(-1)(k-1)/k2; sc=sc+(-1)(k-1)/(2*k-1)3; sd=sd+sin(2*k-1)/(2*k-1)3; sx=sx+4*(-1)(k+1)/(2*k-1);endsa=vpa(sqrt(8*sa),20)sb=vpa(sqrt(12*sb),20)sc=vpa(32*sc)(1/3),20)sd=vpa(1+sqrt(1+32*sd)/2,20)sx=vpa(s,20)结果:>> sa = 3.sb =3.sc = 3. sd =3.sx =3. 题目2:基于关系式利用蒙特卡洛方法近似计算解:cs=0n= for i=1:n a=rand(1,2); a(1)<1&a(1)>0; a(2)<(1)&a(2)>0; if a(2)<=1/(1+a(1)2) cs=cs+1 endendm=4*cs/n结果:m =3.1441题目3:设有一制作均匀的冰激淋可以看成由圆锥面z=和球面围成,采用取随机数的方法,用蒙特卡洛法计算这个冰激淋的体积。解: nSamples = ;nCount = 0;for i = 1 : nSamples x = rand * 2 - 1; y = rand * 2 - 1; z = rand * 2; if ( (x2+y2+(z-1)2) <= 1 && (z2 >= x2+y2) ) nCount = nCount + 1; endendV = nCount / n * 8 V = 3.1526题目4:使用计算机仿真方法求解下述问题:在正方形的四个顶点上各有一人,如下图所示,在某一时刻,四人同时出发以匀速按逆时针方向追赶下一个人,如果他们始终保持对准目标,试确定每个人的行进路线。解:%追击问题 clear zb=0,0;10,0;10,10;0,10;%原始坐标点设置 v=0.3,0.3,0.3,0.3;%速度设置 t=0.01;%最小时间步长 d0=0.05;%判断追到的最小距离 s=size(zb);%确认追击人数 for i=1:10000 zb(s(1,1)+1,:,i)=zb(1,:,i);%使最后一人的追击对象变成第一人,做成环式追击 zbjl(:,:,i)=zb(:,:,i);%坐标数据记录 if sqrt(zb(1,1,i)-zb(2,1,i)2+(zb(1,2,i)-zb(2,2,i)2)<d0%判断结束条件,这里是第一人追到第二人为结束条件 break end for j=1:s(1,1) x=zb(j+1,1,i)-zb(j,1,i);%计算追击2人的坐标差 y=zb(j+1,2,i)-zb(j,2,i); zb(j,1,i+1)=zb(j,1,i)+v(j)*t*x/sqrt(x2+y2);%通过坐标差计算和速度计算出在时间步长的时间内坐标移动的位移 zb(j,2,i+1)=zb(j,2,i)+v(j)*t*y/sqrt(x2+y2); end end s=size(zbjl); hold on for j=1:s(1,1)-1%绘图 for i=1:s(1,3) x(i)=zbjl(j,1,i); y(i)=zbjl(j,2,i); end plot(x,y) end 第四次实验题目1.有一形状较为复杂,但表面很光滑的曲面工件。通过科学手段,将其放置于某一空间坐标系下,测得曲面上若干个点的坐标如下:xy-5-4-3-2-1012345-513.6-8.2-14.8-6.61.40-3.81.413.616.80-4-8.2-15.8-7.92.23.800.67.310.10-16.8-3-14.8-7.92.55.82.302.75.10-10.1-13.7-2-6.62.25.93.0-0.301.90-5.1-7.3-1.4-11.43.82.3-0.3-0.900-1.7-2.7-0.63.80000000000001-3.80.62.71.7000.90.3-2.3-3.8-1.421.47.35.10-1.700.3-3.1-5.8-2.26.6313.610.10-5.1-2.70-2.3-5.8-2.57.914.8416.80-10.1-7.3-0.60-3.8-2.27.915.88.25016.3-13.6-1.43.80-1.46.614.88.2-13.6要求:(1) 画出该区面工件的图形;(2) 在已知相邻的横,纵坐标之间分别插入三个分点,用interp2命令计算出所有点处的竖坐标,画出相应的插值曲面;分别用不同的方法求出该区面工件表面积的近似值。(1)解:x=-5:1:5;y=-5:1:5;z=13.6,-8.2,-14.8,-6.6,1.4,0,-3.8,1.4,13.6,16.8,0; -8.2,-15.8,-7.9,2.2,3.8,0,0.6,7.3,10.1,0,-16.8; -14.8,-7.9,2.5,5.8,2.3,0,2.7,5.1,0,-10.1,-13.7; -6.6,2.2,5.9,3.0,-0.3,0,1.9,0,-5.1,-7.3,-1.4; 1.4,3.8,2.3,-0.3,-0.9,0,0,-1.7,-2.7,-0.6,3.8; 0,0,0,0,0,0,0,0,0,0,0; -3.8,0.6,2.7,1.7,0,0,0.9,0.3,-2.3,-3.8,-1.4; 1.4,7.3,5.1,0,-1.7,0,0.3,-3.1,-5.8,-2.2,6.6; 13.6,10.1,0,-5.1,-2.7,0,-2.3,-5.8,-2.5,7.9,14.8; 16.8,0,-10.1,-7.3,-0.6,0,-3.8,-2.2,7.9,15.8,8.2; 0,16.3,-13.6,-1.4,3.8,0,-1.4,6.6,14.8,8.2,13.6;x0,y0=meshgrid(-5:1:5,-5:1:5);z1=interp2(x,y,z,x0,y0,'linear');%线形插值z2=interp2(x,y,z,x0,y0,'cubic');%三次插值z3=interp2(x,y,z,x0,y0,'spline');%三次样条插值mesh(x0,y0,z1)%mesh(x0,y0,z2)%mesh(x0,y0,z3)结果:(2)解:x=-5:1:5;y=-5:1:5;xb,yb=meshgrid(x,y);zb=13.6,-8.2,-14.8,-6.6,1.4,0,-3.8,1.4,13.6,16.8,0; -8.2,-15.8,-7.9,2.2,3.8,0,0.6,7.3,10.1,0,-16.8; -14.8,-7.9,2.5,5.8,2.3,0,2.7,5.1,0,-10.1,-13.7; -6.6,2.2,5.9,3.0,-0.3,0,1.9,0,-5.1,-7.3,-1.4; 1.4,3.8,2.3,-0.3,-0.9,0,0,-1.7,-2.7,-0.6,3.8; 0,0,0,0,0,0,0,0,0,0,0; -3.8,0.6,2.7,1.7,0,0,0.9,0.3,-2.3,-3.8,-1.4; 1.4,7.3,5.1,0,-1.7,0,0.3,-3.1,-5.8,-2.2,6.6; 13.6,10.1,0,-5.1,-2.7,0,-2.3,-5.8,-2.5,7.9,14.8; 16.8,0,-10.1,-7.3,-0.6,0,-3.8,-2.2,7.9,15.8,8.2; 0,16.3,-13.6,-1.4,3.8,0,-1.4,6.6,14.8,8.2,-13.6;xc=-5:0.25:5;yc=-5:0.25:5;xcb,ycb=meshgrid(xc,yc);zcb=interp2(xb,yb,zb,xcb,ycb);mesh(xcb,ycb,zcb)程序:x=-5:1:5;y=-5:1:5;xb,yb=meshgrid(x,y);zb=13.6,-8.2,-14.8,-6.6,1.4,0,-3.8,1.4,13.6,16.8,0;-8.2,-15.8,-7.9,2.2,3.8,0,0.6,7.3,10.1,0,-16.8;-14.8,-7.9,2.5,5.8,2.3,0,2.7,5.1,0,-10.1,-13.7;-6.6,2.2,5.9,3.0,-0.3,0,1.9,0,-5.1,-7.3,-1.4;1.4,3.8,2.3,-0.3,-0.9,0,0,-1.7,-2.7,-0.6,3.8;0,0,0,0,0,0,0,0,0,0,0;-3.8,0.6,2.7,1.7,0,0,0.9,0.3,-2.3,-3.8,-1.4;1.4,7.3,5.1,0,-1.7,0,0.3,-3.1,-5.8,-2.2,6.6;13.6,10.1,0,-5.1,-2.7,0,-2.3,-5.8,-2.5,7.9,14.8;16.8,0,-10.1,-7.3,-0.6,0,-3.8,-2.2,7.9,15.8,8.2;0,16.3,-13.6,-1.4,3.8,0,-1.4,6.6,14.8,8.2,-13.6;XI,YI=meshgrid(xb,yb);Fx,Fy=gradient(zb,0.1,0.1);S=sqrt(1+Fx.2+Fy.2)*0.01.*( isnan(zb) ) ;sum(S(isnan(S)结果:ans = 76.7454题目2.煤矿的储量估计,表14-10给出了某露天煤矿在平面矩形区域(800 m × 600 m)内,纵横均匀的网格交点处测得的煤层厚度(单位:m),由于客观原因,有些点无法测量煤层厚度用/标出,其中每一网格均为10 m × 8 m的小矩形,试根据这些数据,用不同的方法估算该矩形区域煤矿的储藏量(体积):表14-10 煤层厚度数据ABCDEFGHIGK1*12.513.517.2*8.814.78.013.0*2*15.618.2136.48.99.211.7*3*1213.517.816.913.2*47.512.614.918.717.717.514.713*58.97.812.413.515.717.611.79.69.29.58.66*13.713.616.512.58.79.7*7*8.611.812.511.313.4*解:x=0:80:800;y=0:100:600;z=14.2,14.1,12.5,13.5,17.2,12.9,8.8,14.7,8.0,13.0,10.3;19.1,17.9,16.7,15.6,18.2,13,6.4,8.9,9.2,11.7,7.0;12.4,12,13.5,13.5,17.8,16.9,13.2,16.5,17.1,17.7,18.3;7.5,12.6,14.9,18.7,17.7,17.5,14.7,13,9.9,7.6,6.5;8.9,7.8,12.4,13.5,15.7,17.6,11.7,9.6,9.2,9.5,8.6;8.2,9.3,11.7,13.7,13.6,16.5,12.5,8.7,9.7,7.6,9.5;8.1,10.8,8.6,11.8,12.5,11.3,13.4,11.0,8.4,5.0,0.88;x0,y0=meshgrid(0:1:800,0:1:600);z1=interp2(x,y,z,x0,y0,'linear');%线形插值z2=interp2(x,y,z,x0,y0,'cubic');%三次插值z3=interp2(x,y,z,x0,y0,'spline');%三次样条插值%surf(x0,y0,z1)surf(x0,y0,z2)%surf(x0,y0,z3)shading interp;for i=1:601for j=1:801 %分成1×1的小块M(i,j)=z2(i,j); %线形插值时体积%M(i,j)=z2(i,j); %三次插值时体积%M(i,j)=z3(i,j); %三次样条插值时体积endendsum(sum(M)结果:ans = 6.0964e+006课程体会,致谢通过MATLB的学习,熟悉了matlab 的操作环境,掌握了相关的操作命令函数,了解了相关实际问题的处理、解决方法。同时通过本课程的学习,复习了包括数学分析、高等代数、计算方法、常微分方程等相关学科的知识内容。这门课对培养数学思维、解决实际问题的能力有特别的作用和意义,学生在这门课的学习中受益不浅。但通过阅读相关资料、学术期刊,可以看出:matlab的在信号处理、影像处理、神经网络分析、系统仿真、模糊系统设计等领域应用十分广泛,仅仅靠短时间的学习还不能完全掌握其要领,还需要进一步学习。扎实学习数学知识,培养数学思维能力,才能起到事半功倍的效果。专心-专注-专业