LAB 9: Use constrained minimization function tools for solving constrained linear and nonlinear
problems using fmincon.
fmincon: Syntax Description x = fmincon(fun,x0,A,b) x = fmincon(fun,x0,A,b) starts at x0 and attempts to find a minimizer x of the function described in fun subject to the linear inequalities A*x ≤ b. x0 can be a scalar, vector, or matrix. x = fmincon(fun,x0,A,b,Aeq,beq) x = fmincon(fun,x0,A,b,Aeq,beq) minimizes fun subject to the linear equalities Aeq*x = beq and A*x ≤ b. If no inequalities exist, set A = [] and b = []. x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub) x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub) defines a set of lower and upper bounds on the design variables in x, so that the solution is always in the range lb ≤ x ≤ ub. If no equalities exist, set Aeq = [] and beq = []. If x(i) is unbounded below, set lb(i) = -Inf, and if x(i) is unbounded above, set ub(i) = Inf. x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon) x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon) subjects the minimization to the nonlinear inequalities c(x) or equalities ceq(x) defined in nonlcon. fmincon optimizes such that c(x) ≤ 0 and ceq(x) = 0. If no bounds exist, set lb = [] and/or ub = []. x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options) x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options) minimizes with the optimization options specified in options. Use optimoptions to set these options. If there are no nonlinear inequality or equality constraints, set nonlcon = []. x = fmincon(problem) x = fmincon(problem) finds the minimum for problem, where problem is a structure described in Input Arguments. Create the problem structure by exporting a problem from Optimization app, as described in Exporting Your Work. [x,fval] = fmincon(___) [x,fval] = fmincon(___), for any syntax, returns the value of the objective function fun at the solution x. [x,fval,exitflag,output] = fmincon(___) [x,fval,exitflag,output] = fmincon(___) additionally returns a value exitflag that describes the exit condition of fmincon, and a structure output with information about the optimization process. [x,fval,exitflag,output,lambda,grad,hessian] = fmincon(___) [x,fval,exitflag,output,lambda,grad,hessian] = fmincon(___) additionally returns: lambda — Structure with fields containing the Lagrange multipliers at the solution x. grad — Gradient of fun at the solution x. hessian — Hessian of fun at the solution x. Program 1: Find the values of x that minimize f(x)=-x1x2x3, starting at point x=[10;10;10], subject to constraints: 0≤ x1+ 2x2+2 x3≤72: Script: filename: lab9a function f=lab9a(x) f=-x(1)*x(2)*x(3); Command Window: a=[-1,-2,-2;1,2,2]; b=[0;72]; x0=[10;10;10]; [x,fval]=fmincon(@lab9a,x0,a,b)
Program 2: Linear Inequality Constraints
Find the minimum value starting from the point [-1,2], constrained to have x(1)+2x(2)≤1. Express this constraint in the form Ax <= b by taking A = [1,2] and b = 1. Notice that this constraint means that the solution will not be at the unconstrained solution (1,1), because at that point x(1)+2x(2)=3>1. f(x)=100*(x(2)-x(1)^2)^2+(1-x(1))^2 Command Window: fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2 x0 = [-1,2]; A = [1,2]; b = 1; x = fmincon(fun,x0,A,b)
Program 3: Linear Inequality and Equality Constraint
Find the minimum value starting from the point [0.5,0], constrained to have x(1)+2x(2)≤1 and 2x(1)+x(2)=1. Express the linear inequality constraint in the form A*x <= b by taking A = [1,2] and b = 1. Express the linear equality constraint in the form Aeq*x = beq by taking Aeq = [2,1] and beq = 1. f(x)=100*(x(2)-x(1)^2)^2+(1-x(1))^2 Command Window: fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2 x0 = [0.5,0]; A = [1,2]; b = 1; Aeq = [2,1]; beq = 1; x = fmincon(fun,x0,A,b,Aeq,beq)