Message Boards Message Boards

Solve two equations of motion?

Posted 7 years ago

Hi guys, Having a bit of an issue with one of my inputs on mathematica, i have two equations of motion for a complex system and trying to get a solution out of it. Keep getting the error message: NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.`. But, as far as i'm concerned I have assigned a value to all my variables except the two i'm solving for.

My input is below:

eq1 := ?''[t] -  A w^2 l Cos[?[t]] Sin[w t] - 
   l g  Sin[?[t]] + (l ?'[t]^2 Sin[?[t] - ?[t]] + l ?''[t] Cos[?[t] - ?[t]])/? == 0
eq2 := ?''[t] - (g Sin[?[t]] + A w^2 Cos[?[t]] Sin[w t] + 
      l ?'[t] Sin[?[t] - ?[t]] - l ?''[t] Cos[?[t] - ?[t]])/L == 0 

With[{g = 9.81, ? = 20, l = 1, L = 1, A = 1, w = 50}, 
 sol = NDSolve[{eq1, eq2, ?'[0.1] == 5, ?'[0.1] == 1, ?[0] == 0, ?[0] == 0}, {?[t], ?[t]}, {t, 10}]]

NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.`.

Thanks.

POSTED BY: B Patel

One way to diagnose this is to add something like Print[sol] in the With. It will show quite clearly that the substitution did not take place. Why is that? Because it is a literal substitution, and the variables g et al do not appear literally in the body of the With statement.

Here is a way to proceed. Define the ODE system inside the With statement.

With[{g = 9.81, \[Alpha] = 20, l = 1, L = 1, A = 1, w = 50},
 eq1 = \[Theta]''[t] - A w^2 l Cos[\[Theta][t]] Sin[w t] - 
    l g Sin[\[Theta][
       t]] + (l \[Phi]'[t]^2 Sin[\[Theta][t] - \[Phi][t]] + 
       l \[Phi]''[t] Cos[\[Theta][t] - \[Phi][t]])/\[Alpha] == 0; 
 eq2 = \[Phi]''[
     t] - (g Sin[\[Phi][t]] + A w^2 Cos[\[Phi][t]] Sin[w t] + 
       l \[Theta]'[t] Sin[\[Theta][t] - \[Phi][t]] - 
       l \[Theta]''[t] Cos[\[Theta][t] - \[Phi][t]])/L == 0;
 sol = NDSolve[
   {eq1,  eq2, \[Theta]'[0.1] == 5, \[Phi]'[0.1] == 1, \[Theta][0] == 
      0, \[Phi][0] == 0}, {\[Theta][t], \[Phi][t]}, {t, 10}];
 sol]

This runs for me without error and produces a solution.

--- edit ---

Better way: force evalution inside With so the substitution of variables can occur.

With[{g = 9.81, \[Alpha] = 20, l = 1, L = 1, A = 1, w = 50},
 sol = Evaluate[
   NDSolve[{eq1,  eq2, \[Theta]'[0.1] == 5, \[Phi]'[0.1] == 1, \[Theta][0] ==  0, \[Phi][0] == 0}, {\[Theta][t], \[Phi][t]}, {t, 10}]];
 sol]

--- end edit ---

POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract