2007: J F M A M J J A S O N D
2008: J F M A M J J A S O N D
2009: J F M A M J J A S O N D
2010: J F M A M J J A S O N D
2011: J F M A M J J A S O N D
2012: J F M A M J J A S O N D
2013: J F M A M J J A S O N D

Blog, by date: 2012_feb

from 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

 begin{split} min qquad & g^Td + frac12 d^TWd text{subject to} qquad & c_L leq Ad leq c_U 						 & d_L leq d leq d_U end{split}

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)

diagram 

I came across this post. The basic idea is the guy wants to maximize L_1+L_2 constrained to this box, where L_i is the length of beam i. It's constrained to be a 61 cmx61 cm box, but one beam must start from 10cm up from the bottom right corner and the beams must meet at a point along the top of the box. I added the further assumption that the other beam must end in the bottom left corner.

 begin{split} 	T_1 =& L_1sintheta_1 	51 =& L_2costheta_1 	T_2 =& L_2sintheta_2 	61 =& L_2costheta_2 end{split}

which fall from simple trig. There's one more equation, which constrains the side length to 61 cm:

 T_1 + T_2 = 61
Next, I squared each pair of equations to get
 begin{split} 	T_1^2 =& L_1^2sin^2theta_1 	51^2 =& L_1^2cos^2theta_1 	end{split}implies 	L_1^2 = T_1^2 + 51^2

and similarly L_2^2=61^2+T_2^2.

I'm planning on using MATLAB's FMINCON, which means I need to formulate this as a minimization problem. This is accomplished by observing

 	max f(x) iff min -f(x).

Therefore, the final nonlinear program that I want to solve is

 begin{split} 	min qquad & -L_1 - L_2 	text{subject to} qquad & L_1^2 -T_1^2 - 51^2 = 0 							 & L_2^2 -T_2^2 - 61^2 = 0 							 & T_1 + T_2 - 61 = 0 end{split}

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!

Powered by Olark