Blog, by date: 2012_febfrom the desk of travis johnson.
cplex matlab interface (from 2012/02/01)Just for my own reference, I'm documenting the interface to CPLEX. CPLEX expects a problem in the form
and is called by
cplex = Cplex('test');
cplex.Param.feasopt.tolerance.Cur = 1e-8;
if params.printLevel < 8
cplex.DisplayFunc = [];
end
cplex.Model.sense = 'minimize';
cplex.Param.qpmethod.Cur = 1;
cplex.addCols(gk,[],bl-xk,bu-xk);
cplex.addRows(-ck, A0, -ck);
cplex.Model.Q = W;
cplex.Model.obj = g;
cplex.Model.lb = d_L;
cplex.Model.ub = d_U;
cplex.Model.lhs= c_L;
cplex.Model.rhs= c_U;
cplex.solve();
a trig problem solved in MATLAB (from 2012/02/01)
which fall from simple trig. There's one more equation, which constrains the side length to 61 cm:
and similarly I'm planning on using MATLAB's FMINCON, which means I need to formulate this as a minimization problem. This is accomplished by observing
Therefore, the final nonlinear program that I want to solve is
which can be solved with the matlab program
function xsol = solveproblem()
f = @(x) -x(1)-x(2);
x0 = [0;0;0;0]; LB=[0;0;0;0];
settings = optimset('TolFun',1e-8,'Algorithm','interior-point');
xsol = fmincon(f,x0,[],[],[],[],LB,[],@nonlincon,settings);
function [c,ceq]=nonlincon(x)
l1=x(1);l2=x(2);t1=x(3);t2=x(4);
c=[];
ceq = [l1^2-t1^2-51^2;
l2^2-t2^2-61^2;
t1 + t2 - 61];
end
end
When run, this produces a length 140.5 pair of beams. Hooray! |