MATLAB作业word版

上传人:日度 文档编号:164281194 上传时间:2021-01-27 格式:DOC 页数:7 大小:144.50KB
返回 下载 相关 举报
MATLAB作业word版_第1页
第1页 / 共7页
MATLAB作业word版_第2页
第2页 / 共7页
MATLAB作业word版_第3页
第3页 / 共7页
MATLAB作业word版_第4页
第4页 / 共7页
MATLAB作业word版_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《MATLAB作业word版》由会员分享,可在线阅读,更多相关《MATLAB作业word版(7页珍藏版)》请在金锄头文库上搜索。

1、 MATLAB作业6 1、用图解的方式找到下面两个方程构成的联立方程的近似解。(注:在图上可用局部放大的方法精确读出交点值)解: ezplot(x2+y2-3*x*y2);hold onezplot(x3-x2=y2-y) syms x1 x2 y1 y2; x1=0.4012;y1=0.8916;x2=1.5894;y2=0.8185; vpa(x12+y12-3*x1*y12)ans = -0.0008904940159999430449033752665855 vpa(x22+y22-3*x2*y22) ans = 0.0017159735499996386920429358724505

2、2、在图形绘制语句中,若函数值为不定式NaN ,则相应的部分不绘制出来,试利用该规律绘制的表面图,并剪切下的部分。解: x,y=meshgrid(-1:.1:1); z=sin(x.*y); ii=find(x.2+y.2 z(ii)=NaN; surf(x,y,z)1 / 73、试用图解法求解下面的一元和二元方程,并验证得出的结果。解:(1) ezplot(exp(-(x+1)2+pi/2)*sin(5*x+2),-4 4) hold on, line(-4,4,0,0)(2) ezsurf(x2+y2+x*y)*exp(-x2-y2-x*y) x,y=meshgrid(-3:0.1:3);

3、z=(0.1*x.2+0.1*y.2+x.*y).*exp(-x.2-y.2-x.*y); C,h=contour(x,y,z,-0.1:0.05:0.1)4、用数值求解函数求解习题3中方程的根,并对得出的结果进行检验。解:(1) syms x; x1=solve(exp(-(x+1)2+pi/2)*sin(5*x+2)x1 = -2/5 subs(exp(-(x+1)2+pi/2)*sin(5*x+2),x,x1)ans = 0(2) syms x; y1=solve(x2+y2+x*y)*exp(-x2-y2-x*y)=0,y)y1 = - x/2 + (3(1/2)*x*i)/2 - x

4、/2 - (3(1/2)*x*i)/2 y2=simple(subs(x2+y2+x*y)*exp(-x2-y2-x*y),y,y1) y2 = 0 05、试求解下面的无约束最优化问题。 解: f=inline(100*(x(2)-x(1)2)2+(1-x(1)2+90*(x(4)-x(3)2)+(1-x(3)2)2+10.1*(x(2)-1)2+(x(4)-1)2)+19.8*(x(2)-1)*(x(4)-1),x); x=fminunc(f,1;1;1;1)Warning: Gradient must be provided for trust-region algorithm; usin

5、g line-search algorithm instead. In fminunc at 367 Local minimum found.Optimization completed because the size of the gradient is less thanthe default value of the function tolerance.x = 10.5464 111.2315 6.7823 -111.50416、 试用图解法求解下面的非线性规划问题,并用数值求解算法验证结果。解: x1,x2=meshgrid(0:0.02:1,1:0.02:2); z=x1.3+x

6、2.2+4*x1+4;ii=find(x1-x2+2ii=find(-x1.2+x2-1ii=find(x1ii=find(x2surf(x1,x2,z) min(z(:)ans = 5function c,ce=exc6f4(x)ce=;c=x(1)2-x(2)+1; f_opt=inline(x(1)3+x(2)2+4*x(1)+4,x);A=-1 1; B=2; Aeq=; Beq=; xm=0;0;x=fmincon(f_opt,0;1,A,B,Aeq,Beq,xm,exc6f4)x = 0 17、 试求解此线性规划问题:解: f=0,0,0,0,0,1,1;Aeq=1 1 1 1 0

7、 0 0; -2 1 -1 0 0 -1 1; 0 3 1 0 1 0 1;Beq=4; 1; 9; xm=0;0;0;0;0;0;0; A=; B=;x=linprog(f,A,B,Aeq,Beq,xm)Optimization terminated.x = 0.3952 2.3213 0.5309 0.7526 1.5053 0.0000 0.00008、 试求解下面的二次型规划问题,并用图示的形式解释结果。 解: H=4 -4; -4 8; f=-6 -3; Aeq=; Beq=; A=1 1; 4 1; B=3;9; xm=0;0; x=quadprog(H,f,A,B,Aeq,Beq

8、,xm)Warning: Trust-region-reflective algorithm does not solve this type of problem, using active-set algorithm. You could also try theinterior-point-convex algorithm: set the Algorithm option to interior-point-convex and rerun. For more help, see Choosing the Algorithm inthe documentation. In quadpr

9、og at 371 Optimization terminated.x = 1.9500 1.05009、 试求解下面的非线性规划问题。 解:function y=exc6fun6(x)y=exp(x(1)*(4*x(1)2+2*x(2)2+4*x(1)*x(2)+2*x(2)+1);function c,ce=exc6fun6a(x)ce=;c=x(1)+x(2); x(1)*x(2)-x(1)-x(2)+1.5; -10-x(1)*x(2); A=; B=; Aeq=; Beq=; xm=-10; -10; xM=10; 10;x0=(xm+xM)/2; ff=optimset; ff.T

10、olX=1e-10; ff.TolFun=1e-20; x=fmincon(exc6fun6,x0,A,B,Aeq,Beq,xm,xM,exc6fun6a,ff)Maximum number of function evaluations exceeded;increase OPTIONS.MaxFunEvalsx =0.419473260539100.41947326053910 i=1; x=x0; while (1) x,a,b=fmincon(exc6fun6,x,A,B,Aeq,Beq,xm,xM,exc6fun6a,ff); if b0, break; end i=i+1; end

11、 x,i x =1.18249727581645-1.73976692398900i =510、 试求解01线性规划问题,并用穷举方法检验得出的结果。 解: f=5 7 10 3 5; B=2; 0; 1; ctype=1;1;-1;A=1 -1 5 1 -4; -2 6 -3 -2 2; 0 -2 2 -1 -1;intlist=1;1;1;1;1; xM=intlist; xm=zeros(5,1); res,b=ipslv_mex(f,A,B,intlist,xM,xm,ctype); resans =0 1 1 0 0 (注:本资料素材和资料部分来自网络,仅供参考。请预览后才下载,期待您的好评与关注!)

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号