1
$\begingroup$

I have a manipulator equation of the form:

$M(q){q''} + C(q,q')q'+G(q) = {0}$

where $M, C$ are $6$ x $6$ matrices, and $G, q$ are $6$ x $1$ vectors and $q$ a function of time.

    q = {\[Theta]w[t], \[Theta]sr[t], \[Theta]sl[t], \[Theta]er[t], \[Theta]el[t], \[Theta]o[t]};

I would like to solve the differential equation to determine $q$ as a function of time. The matrices $M$ and $C$, the symbolic expressions of which I have determined, are extremely large and using NDSolve results in insufficient RAM memory.

For given initial conditions, is it possible for me to compute $M$ and $C$ numerically at every time step and then use them as coefficients in solving the ODE each time? So instead of directly solving my manipulator equation, I am forcing my coefficient matrices to be numerical as follows:

    mmat[q1_?(VectorQ[#, NumericQ] &), t1_] := Module[{qm, mmat},
           qm = q1 /. {t -> t1};
           mmat = M /. {\[Theta]w[t] -> qm[[1]], \[Theta]sr[t] -> qm[[2]], \[Theta]sl[t] -> qm[[3]], \[Theta]er[t] -> qm[[4]], \[Theta]el[t] -> qm[[5]], \[Theta]o[t] -> qm[[6]]};
           Return[mmat];
        ];

    MatC[q1_?(VectorQ[#, NumericQ] &), qt_?(VectorQ[#, NumericQ] &)] := Module[{qc, qct, cmatrix}, 
           qc = q1;
           qct = qt; 
           cmatrix = Cm /. {\[Theta]w[t] -> qc[[1]], \[Theta]sr[t] ->qc[[2]], \[Theta]sl[t] -> qc[[3]], \[Theta]er[t] -> qc[[4]], \[Theta]el[t] -> qc[[5]], \[Theta]o[t] -> qc[[6]], \[Theta]w'[t] -> qct[[1]], \[Theta]sr'[t] -> qct[[2]], \[Theta]sl'[t] -> qct[[3]], \[Theta]er'[t] -> qct[[4]], \[Theta]el'[t] -> qct[[5]], \[Theta]o'[t] -> qct[[6]]};
           (* Since C is protected, using Cm for C Matrix *) 
           Return[cmatrix];
        ];

    gvec[q1_?(VectorQ[#, NumericQ] &), t1_] := Module[{gvec}, 
           gvec = G /. {q -> {q1 /. {t -> t1}}}; 
           Return[gvec];
        ]; 

       solnq = NDSolve[{mmat[u[t], t].u''[t] + MatC[u[t], u'[t], t].u'[t] + gvec[u[t], t] == {0, 0, 0, 0, 0, 0}, u'[0] == {0, 0, 0, 0, 0, 0}, u[0] == {0, 0, 0, 0, 0, 0}}, u, {t, 0, 0.1}]

where I replace q with another variable u[t].

Since mmat($M$), MatC($C$) and gvec($G$) are calculated at every time step using the previous ODE solution information, I expected a convergence in finding the solution of the ODE. But I get the following warnings and errors. I expected the first since I was anyway trying to solve the ODE as series of ODEs. But the second error pops up for any initial conditions I use.

    NDSolve::ntdvdae: Cannot solve to find an explicit formula for the derivatives. NDSolve will try solving the system as differential-algebraic equations. >>

    NDSolve::icfail: Unable to find initial conditions that satisfy the residual function within specified tolerances. Try giving initial conditions for both values and derivatives of the functions. >>

I'd appreciate it if someone could guide me to an existing in-build Mathematica function that attempts to do the same as I am or correct my mistake.

Thank you very much.

$\endgroup$
1
  • $\begingroup$ Please provide more detail. $\endgroup$
    – bbgodfrey
    Jul 2, 2015 at 4:03

0