# Time optimization of motion using mathematica

Let us say I have a double pendulum, with the torque equations and the initial and final poisition of the end point of the pendulum. I have constraints on the maximum and minimum values of torques. I need to find a trajectory such that the pendulum reaches the final position in the shortest posible time subject to the constraints of torque. I have done a similar problem on matlab, but not able to figure out how to do it on mathematica.

T1= (I1 + m1*r1^2 + m2*L1^2 + m2*L1*r2*Cos[x1[t] - x2[t]])*
x1''[t] + (I2 + m2*r2^2 + m2*L1*r2*Cos[x1[t] - x2[t]])*x2''[t] -
m2*L1*r2*Sin[x1[t] - x2[t]]*(x1'[t])^2 +
m2*L1*r2*Sin[x1[t] - x2[t]]*(x2'[t])^2 + (m1*r1 + m2*r2)*g*
Cos[x1[t]] + m2*r2*g*Cos[x2[t]];
T2=m2*L1*r2*Cos[x1[t] - x2[t]]*x1''[t] + (I2 + m2*r2^2)*x2''[t] -
m2*L1*r2*Sin[x1[t] - x2[t]]*(x1'[t])^2 + m2*r2*g*Cos[x2[t]];


I need to solve this using NDSolve for known initial values of x,x' and x'' and known final value of x1,x2 and march forward in time. So I need to put this into minimize and pass the guesses of final time to the NDSolve. Is this right? If, it is, how do I do it? Thanks for the help in advance.