《数学软件与数学实验》第三版——P110 优化问题
作者:互联网
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