《MATLAB程序设计实验6报告.docx》由会员分享,可在线阅读,更多相关《MATLAB程序设计实验6报告.docx(11页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、MATLAB程序设计实验6报告MATLAB程序设计实验6解方程和最优化问题求解一实验目的1.把握线性方程组的数值求解方法。2.把握常微分方程的数值求解方法。3.把握非线性方程以及最优化问题的求解方法。二实验内容1.对下列线性病态方程组:1231/21/31/40.951/31/41/50.671/41/51/60.52xxx?=?a)求方程组的解。A=1/2,1/3,1/4;1/3,1/4,1/5;1/4,1/5,1/6;b=0.95,0.67,0.52;x=Abx=1.20000.60000.6000b)将方程组右边的向量元素b30.52修改为0.53,再次求方程组的解。比拟b3的变化和解的
2、相对变化。A=1/2,1/3,1/4;1/3,1/4,1/5;1/4,1/5,1/6;b=0.95,0.67,0.53;x=Abx=3.0000-6.60006.6000c)求系数矩阵的条件数,并分析条件数对线性方程组求解的影响。2.求方程的解。a)413010,1xxx+=-函数文件:funx.mfunctionfx=funx(x)fx=x41+x3+1;调用:z=fzero(funx,-1)z=-0.9525b)0sin0,0.5xxxx-=函数文件funx.mfunctionfx=funx(x)fx=x-sin(x)./x;z=fzero(funx,0.5)z=0.8767c)23sin
3、ln70321050yxyzxzxyz?+-=?+-+=?+-=?,000111xyz=?=?=?函数文件:funx.mz=fzero(funx,0.5)z=0.8767调用函数:options=optimset(Display,off);x=fsolve(funx,1,1,1,options)x=0.59912.39592.00503.求常微分方程的数值解。a)()1.2sin100yty+=,()000,5,1fttyt=函数文件:functionyp=funx(t,y)yp=-(1.2+sin(10*t).*y;函数调用:t0=0;tf=5;y0=1;t,y=ode23(funx,t0,
4、tf,y0);tans=Columns1through900.06670.13750.20030.26950.35280.43620.50330.5663Columns10through180.63690.69130.74570.80810.87380.95911.02771.09631.1600Columns19through271.22461.30821.37141.43471.50011.58421.65301.72191.7858Columns28through361.85011.93191.99532.05872.12362.20532.27452.34382.4080Columns
5、37through452.47192.55012.61402.67792.74192.81932.90462.96853.0323Columns46through543.09593.17213.23643.30073.36423.43953.53283.59653.6602Columns55through633.72383.79983.86423.92863.99204.06714.14084.21444.2800Columns64through724.34324.41594.48124.54654.60944.68124.75674.83224.8990Columns73through744
6、.96205.0000yans=Columns1through91.00000.90350.78220.68230.59840.54020.51820.51060.4976Columns10through180.46560.42800.38440.33550.29360.25950.24690.24210.2382Columns19through270.22900.20540.18190.15850.13870.12250.11640.11400.1122Columns28through360.10800.09740.08640.07530.06580.05810.05490.05370.05
7、29Columns37through450.05110.04660.04150.03610.03160.02780.02580.02530.0249Columns46through540.02410.02210.01970.01720.01500.01320.01220.01190.0117Columns55through630.01140.01040.00930.00810.00710.00620.00580.00560.0055Columns64through720.00540.00500.00450.00390.00340.00300.00270.00260.0026Columns73t
8、hrough740.00250.0025b)()2/1cosyytt+=,()000,5,1fttyt=函数文件:functionyp=funx(t,y)yp=-y./(1+t2)+cos(t);函数调用:t0=0;tf=5;y0=1;t,y=ode23(funx,t0,tf,y0);tans=Columns1through900.50000.80161.10331.40771.75372.23012.52152.8129Columns10through182.97273.13263.30013.50913.75494.03754.36374.75845.0000yans=Columns1th
9、rough91.00001.01461.03631.04501.01620.91570.64510.41220.1437Columns10through18-0.0122-0.1699-0.3330-0.5273-0.7327-0.9233-1.0649-1.1040-1.05344.求函数在指定区间的最大值。()2411xfxx+=+,()0,2x函数文件:functionfx=funx(x)fx=-(1+x2)/(1+x4);函数调用:x=fminbnd(funx,0,2)x=0.64365.有400万资金,要求在4年内使用完,若在一年内使用资金x元效益不能再次使用,当年不用的资金能够存入
10、银行,年利率为10%。制订资金的使用方案,使4年效益之和最大。函数文件funx.m:functionfx=funx(x)fx=sqrt(x(1)+sqrt(x(2)+sqrt(x(3)+sqrt(x(4);函数文件fx.m:x0=400,400,400,400;A=1,0,0,0;1.1,1,0,0;1.12,1.1,1,0;1.13,1.12,1.1,1;b=400*1,1.1,1.12,1.13;x,f=fmincon(funx,x0,A,b,)fxMaximumnumberoffunctionevaluationsexceeded;increaseOPTIONS.MaxFunEvals.x=45.075479.575688.918577.6690f=33.8770MATLAB程序设计实验6解方程和最优化问题求解物理与电子学院电信1104李育原1404110604指导老师:赵岩