Group Abstract Group Abstract

Message Boards Message Boards

Faster ways to solve symmetric top problem?

Posted 7 years ago

I'm currently trying to solve the symmetric top problem using Mathematica. It's essentially solving this differential equation:

Sec[\[Theta][t]/
   2] (1 - Cos[\[Theta][t]] + 2 Cos[2 \[Theta][t]] + 
    2 (1 + Cos[\[Theta][t]]) Derivative[1][\[Theta]][t]^2) == 0

(There are parameters, but I have set them to some numerical values in this equation).

I found this implementation Nutation of a Symmetric Top - Wolfram Demonstrations Project but it's quite complicated. So I try to do it with NDSolve:

eqN={Sec[\[Theta][t]/
    2] (1 - Cos[\[Theta][t]] + 2 Cos[2 \[Theta][t]] + 
     2 (1 + Cos[\[Theta][t]]) Derivative[1][\[Theta]][t]^2) == 
  0, \[Theta][0] == 1};

solN = NDSolve[eqN, \[Theta][t], {t, 0, 4}]

On my computer, it gives warnings like: "Maximum number of xxx steps reached at the point t == xxx". And I plot out the solutions using:

plotf = \[Theta][t] /. solN; Plot[plotf, {t, 0, 4}]

The result is like this:

Plot of theta

It looks like the solver won't proceed past when it reach the max/min point of theta, but before that everything is fine.

So here is my question: Without actually manually doing integration like the one in Demonstrations project did, are there any ways to solve it using NDSolve capability of Mathematica?

Thanks in advance!

POSTED BY: Ox Clouding
17 Replies

Try:

eqN = {Sec[?[t]/2] (1 - Cos[?[t]] + 2 Cos[2 ?[t]] + 2 (1 + Cos[?[t]]) Derivative[1][?][t]^2) == 
      0, ?[0] == 1};
solN = NDSolve[eqN, ?[t], {t, 0, 4*Pi}, Method -> {"EquationSimplification" -> "Residual"}]
Plot[Evaluate[?[t] /. solN], {t, 0, 4*Pi}]

enter image description here

1:

 eq = {Sec[?[t]/2] (1 - Cos[?[t]] + 2 Cos[2 ?[t]] + 2 (1 + Cos[?[t]]) Derivative[1][?][t]^2) == 0};
 INIT = Derivative[1][?][0] /. Solve[eq /. t -> 0 /. ?[0] -> 1, Derivative[1][?][0]](*A second initial conditions *)

Then we have: $\theta '(0)=-\sqrt{\frac{-1+\cos (1)-2 \cos (2)}{2 (1+\cos (1))}}$ and $\theta '(0)=\sqrt{\frac{-1+\cos (1)-2 \cos (2)}{2 (1+\cos (1))}}$

 sol = ParametricNDSolve[{eq, ?[0] == 1, ?'[0] == a}, ?, {t, 0, 4*Pi}, {a}, Method -> {"EquationSimplification" -> "Residual"}];
 Plot[{?[(INIT[[1]])][t] /. sol, ?[(INIT[[2]])][t] /. sol}, {t, 0, 4*Pi}]

enter image description here

2:

 eq = {Sec[?[t]/2] (1 - Cos[?[t]] + 2 Cos[2 ?[t]] + 2 (1 + Cos[?[t]]) Derivative[1][?][t]^2) == 0};
 INIT = Derivative[1][?][0] /. Solve[eq /. t -> 0 /. ?[0] -> 1, Derivative[1][?][0]](*A second initial conditions *)
  sol = ParametricNDSolve[{D[eq,t], ?[0] == 1, ?'[0] == a}, ?, {t, 0, 4*Pi}, {a}];
  Plot[{?[(INIT[[1]])][t] /. sol, ?[(INIT[[2]])][t] /. sol}, {t, 0, 4*Pi}]
POSTED BY: Mariusz Iwaniuk

Ox,

As to your original question.

But I am more confused. Why this solving method avoids the problem? I couldn't find any description of this "Residual" thing in Mathematica documentation. Is it more robust than default method or what?

I had a chance to look at your equations. The Sqrt function has a discontinuous slope at zero so it interferes with integrators because they rely on the slope. The integrator is jumping into the complex solution space and can't return. Reducing step size does not help.

The best way to solve this is to turn it into a DAE. This is your new equivalent system when you use

Method -> {"EquationSimplification" -> "Residual"}

If you enter:

NDSolve[{\[Theta]'[t] == thPrime[t], 
  eqN[[1]] /. \[Theta]'[t] -> thPrime[t], \[Theta][0] == 1}, {\[Theta][t], 
  thPrime}, {t, 0, 4}]

This NDSolve is equivalent to yours but it throws no errors. In this case I am manually doing what "Residual" is doing.

In every NDSolve one step along the way is to solve for the derivatives. In summary, the "Residual" method is not a better approach but a way to convert an ODE into a DAE to avoid a problem associated with solving for the derivative.

A description of the details for DAE's and the "Residual" method can be found here

A detailed description of the inner workings of NDSolve can be found here

Regards,

Neil

POSTED BY: Neil Singer

Here is the spinning top model in WSM. I sent it spinning and moving in one direction and then hit it with an off center force at 2 seconds to send it off precessing.

enter image description here

Here is the animation:

enter image description here

POSTED BY: Neil Singer
POSTED BY: Neil Singer

Ox,

What version of MMA are you running? On my version the NDSolve completes for all 4 seconds using the manually formed DAE formulation.

You are correct that you specified the problem in the form of f(x,x',t)==0. However, NDSolve goes through a series of steps in solving the problem. One step ("EquationSimplification") is to solve your equation again to put it in a new form. The default form is x'=f(x,t). When it does this, it gets a Sqrt on the right hand side which leads to your numerical problem. A second alternative is to use "Residual". This option takes your equation and substitutes new variables for each of the derivatives so you have an expression g(x,newx,t)==0 where the newx's are the derivatives in the original expression. Now this problem is a DAE -- you have an algebraic equation relating the x's and the newx's and you have differential equations relating x'[t] == newx[t].

If you want to view "under the hood" you can use the following commands to see what MMA is actually doing:

Needs["DifferentialEquations`InterpolatingFunctionAnatomy`"];
Needs["DifferentialEquations`NDSolveUtilities`"];

state = First@
   NDSolve`ProcessEquations[eqN, {\[Theta][t]}, {t}, 
    Method -> {"EquationSimplification" -> "Residual"}];
state["NumericalFunction"]["FunctionExpression"]

Out[25]= Function[{t, \[Theta], \[Theta]$12339105}, {(1 - 
     Cos[\[Theta]] + 2 \[Theta]$12339105^2 (1 + Cos[\[Theta]]) + 
     2 Cos[2 \[Theta]]) Sec[\[Theta]/2]}]

state = First@NDSolve`ProcessEquations[eqN, {\[Theta][t]}, {t}];
state["NumericalFunction"]["FunctionExpression"]

Out[27]= Function[{t, \[Theta]}, {-(
   Sqrt[-1 + Cos[\[Theta]] - 2 Cos[2 \[Theta]]]/Sqrt[
   2 + 2 Cos[\[Theta]]])}]

Note that the residual case adds a new variable, the original EquationSimplification results in a Sqrt[].

(as an aside: Note that you only get one branch of the solution using the DAE approach and there is a second branch that you can get by adding a (consistent) initial condition to the problem (see the example that Mariusz pointed to in the NDSolve docs under "Method" option.)

Regards

Neil

POSTED BY: Neil Singer
POSTED BY: Neil Singer
Posted 7 years ago
POSTED BY: Ox Clouding
Posted 7 years ago
POSTED BY: Ox Clouding
Posted 7 years ago
POSTED BY: Ox Clouding
Posted 7 years ago
POSTED BY: Ox Clouding
Posted 7 years ago

Thanks for making this!

Although I personally find solving DEs are more intuitive for a simple problem like this, I think WSM will save a lot of time in many other situations.

POSTED BY: Ox Clouding

That should teach me not to post without actually looking at the equations in detail! Sorry for the misinformation. Good catch Mariusz!

from what I see on the Systemmodeler webpage, it's don't have a physics interface built-in that one can draw, say, a ellipsoid and specify the gravity and fix point. So how does one simulate this? Do we have to manually put in the differential equation?

As to SystemModeler, you would model the top as a rigid body using the Multibody library elements -- specify the mass and inertia properties, the location of the center of mass and the contact point. Constrain the contact point on a surface and give it some initial conditions. SystemModeler derives the equations of motion and solves them, including an animation. There is a gyroscope example in the WSM examples that shows a rotating, swinging body. Unfortunately I do not see a closer example. If I get a chance, I will knock up a quick model and post it for you.

Regards,

Neil

POSTED BY: Neil Singer

Hello

I'm ordinary user not Jedi Master in Mathematica. I only know how much it is written in the documentation. About "Residual" find here: (NDSolve->Options->Method->EquationSimplification)

Regards MI

POSTED BY: Mariusz Iwaniuk
Posted 7 years ago

[Double posted, please delete]

POSTED BY: Ox Clouding
Posted 7 years ago

This maybe off topic but, from what I see on the Systemmodeler webpage, it's don't have a physics interface built-in that one can draw, say, a ellipsoid and specify the gravity and fix point. So how does one simulate this? Do we have to manually put in the differential equation?

POSTED BY: Ox Clouding
Posted 7 years ago
POSTED BY: Ox Clouding
Posted 7 years ago
POSTED BY: Ox Clouding
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard