ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

《数学软件与数学实验》第三版——P110 优化问题

2022-05-19 22:31:07  阅读:209  来源: 互联网

标签:4.4 P110 04 第三版 数学 found 4.2338 x0 tolerance


workweek13

Contents

《数学软件与数学实验》第三版——P110 优化问题

%2022/5/17

例4.4.1

clear all
x = -10:0.1:10;
f = x.^3.*exp(-x);
plot(x,f)
f1 = '-x.^3.*exp(-x)';
fminbnd(f1,-10,10)
ans =

    3.0000

例4.4.2

clear all
x0 = [1,1];
[x,fval] = fminunc('wxy1',x0)
Local minimum found.

Optimization completed because the size of the gradient is less than
the value of the optimality tolerance.


x =

     1     0


fval =

     0

例4.4.3

clear all
x = 20:120;
y = wxy2(x);
plot(x,y)
[x0,y0] = fminsearch('wxy2',60)
x0 =

   65.4545


y0 =

  241.6609

例4.4.4

clear all
x0 = [1,1,1,1,1];
A = [1,1,1,1,1;1,2,2,1,6;2,1,6,0,0;0,0,1,1,5];
b = [400;800;200;200];
lb = [0;0;0;0;0];
ub = [99;99;99;99;99];
[x,fval] = fmincon('wxy',x0,A,b,[],[],lb,ub)
h =

     7


h =

    7.0000


h =

     7


h =

    7.0000


h =

    7.0000


h =

    7.0000


h =

 -125.2961


h =

 -125.2961


h =

 -125.2961


h =

 -125.2961


h =

 -125.2961


h =

 -125.2961


h =

  -5.2482e+03


h =

  -5.2482e+03


h =

  -5.2482e+03


h =

  -5.2482e+03


h =

  -5.2482e+03


h =

  -5.2482e+03


h =

  -2.3763e+04


h =

  -2.3763e+04


h =

  -2.3763e+04


h =

  -2.3763e+04


h =

  -2.3763e+04


h =

  -2.3763e+04


h =

  -4.1963e+04


h =

  -4.1963e+04


h =

  -4.1963e+04


h =

  -4.1963e+04


h =

  -4.1963e+04


h =

  -4.1963e+04


h =

  -4.2290e+04


h =

  -4.2290e+04


h =

  -4.2290e+04


h =

  -4.2290e+04


h =

  -4.2290e+04


h =

  -4.2290e+04


h =

  -4.2331e+04


h =

  -4.2331e+04


h =

  -4.2331e+04


h =

  -4.2331e+04


h =

  -4.2331e+04


h =

  -4.2331e+04


h =

  -4.2335e+04


h =

  -4.2335e+04


h =

  -4.2335e+04


h =

  -4.2335e+04


h =

  -4.2335e+04


h =

  -4.2335e+04


h =

  -4.2338e+04


h =

  -4.2338e+04


h =

  -4.2338e+04


h =

  -4.2338e+04


h =

  -4.2338e+04


h =

  -4.2338e+04


h =

  -4.2338e+04


h =

  -4.2338e+04


h =

  -4.2338e+04


h =

  -4.2338e+04


h =

  -4.2338e+04


h =

  -4.2338e+04


h =

  -4.2338e+04


h =

  -4.2338e+04


h =

  -4.2338e+04


h =

  -4.2338e+04


h =

  -4.2338e+04


h =

  -4.2338e+04


Local minimum found that satisfies the constraints.

Optimization completed because the objective function is non-decreasing in 
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.


x =

    0.0000    0.0000   33.3333   99.0000    0.0000


fval =

  -4.2338e+04

最优化问题附加作业

练习1

f=[-3/4,150,-1/50,6]; Aeq=[]; Beq=[]; %目标函数与等式约束
A=[1/4,-60,-1/50,9; 1/2,-90,-1/50,3]; B=[0;0]; %线性不等式约束
xm=[-5;-5;-5;-5]; xM=[Inf;Inf;1;Inf]; %决策变量边界
F=optimset; F.TolX=eps; %精度设定
[x,f0,key,c]=linprog(f,A,B,Aeq,Beq,xm,xM,[0;0;0;0],F) %直接求解

clear P; P.f=f; P.Aineq=A; P.Bineq=B; P.solver='linprog';
P.lb=xm; P.ub=xM; P.options=F; linprog(P) %用结构体描述线性规划
The dual-simplex algorithm uses a built-in starting point;
ignoring supplied X0.

Optimal solution found.


x =

   -5.0000
   -0.1947
    1.0000
   -5.0000


f0 =

  -55.4700


key =

     1


c = 

  包含以下字段的 struct:

         iterations: 3
    constrviolation: 0
            message: 'Optimal solution found.'
          algorithm: 'dual-simplex'
      firstorderopt: 5.9212e-15


Optimal solution found.


ans =

   -5.0000
   -0.1947
    1.0000
   -5.0000

练习2

f=[22,-5,7,10,-8,-8,9];
Aeq=[0,1,-2,-1,0,5,1; 5,-3,1,2,3,2,1]; beq=[2; -2];
A=[3,0,-2,-2,0,0,3; 2,3,1,0,0,3,1;
2,4,-4,2,-3,2,2; 0,-2,2,0,3,-2,-2;
-5,-1,1,-1,0,5,1; 1,-2,2,-3,1,6,4; 0,3,-5,-1,3,3,3];
b=[4; 1; 2; 4; 3; 3; 2]; xm=-5*ones(7,1);
[x,f0,flag]=linprog(f,A,b,Aeq,beq,xm)
Optimal solution found.


x =

   -1.9505
   -3.1237
   -5.0000
    3.0742
    0.1432
    0.4648
   -4.1263


f0 =

  -73.5521


flag =

     1

练习3

P=optimproblem;
x=optimvar('x',3,1,'LowerBound',0);
P.Objective=-2*x(1)+3*x(2)-4*x(3)+4*x(1)^2+2*x(2)^2+...
      7*x(3)^2-2*x(1)*x(2)-2*x(1)*x(3)+3*x(2)*x(3);
P.Constraints.c1=2*x(1)+x(2)+3*x(3) >= 8;
P.Constraints.c2=x(1)+2*x(2)+x(3) <= 7;
P.Constraints.c3=-3*x(1)+2*x(2) <= -5;
sols=solve(P); x0=sols.x
p=prob2struct(P); p.H=(p.H+p.H')/2; x1=quadprog(p)
Solving problem using quadprog.
Your Hessian is not symmetric. Resetting H=(H+H')/2.

Minimum found that satisfies the constraints.

Optimization completed because the objective function is non-decreasing in 
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.


x0 =

    1.7546
    0.1319
    1.4530


Minimum found that satisfies the constraints.

Optimization completed because the objective function is non-decreasing in 
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.


x1 =

    1.7546
    0.1319
    1.4530

标签:4.4,P110,04,第三版,数学,found,4.2338,x0,tolerance
来源: https://www.cnblogs.com/wings-73012/p/16290445.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有