Troubleshooting Mathematica Pendulum Equation: Finding Solutions with NDSolve

  • Context: Mathematica 
  • Thread starter Thread starter DannyS
  • Start date Start date
  • Tags Tags
    Mathematica Pendulum
Click For Summary
SUMMARY

The discussion focuses on troubleshooting the pendulum motion equation using Mathematica's NDSolve function. The equation provided involves multiple variables, including θ1 and θ2, and parameters such as g, m1, and m2. Users report that reducing the accuracy and precision settings allows NDSolve to find solutions, although increasing these settings leads to complex results. The discussion emphasizes the importance of adjusting solver options to achieve desired outcomes.

PREREQUISITES
  • Understanding of differential equations, particularly in the context of pendulum motion.
  • Familiarity with Mathematica version 12.3 or later and its NDSolve function.
  • Knowledge of numerical methods for solving ordinary differential equations (ODEs).
  • Basic skills in data visualization using ListPlot in Mathematica.
NEXT STEPS
  • Explore the use of NDSolve options such as AccuracyGoal and PrecisionGoal in Mathematica.
  • Learn about the implications of complex solutions in differential equations.
  • Investigate alternative numerical methods for solving ODEs, such as Runge-Kutta methods.
  • Study the physical principles behind pendulum motion to better understand the expected behavior of solutions.
USEFUL FOR

Mathematics students, physicists, and engineers working with dynamic systems, particularly those using Mathematica for numerical simulations and visualizations of differential equations.

DannyS
Messages
3
Reaction score
0
I am trying to input the equation of motion for a pendulum:
θ1'' = −g (2 m1 + m2) sin θ1 − m2 g sin(θ1 − 2 θ2) − 2 sin(θ1 − θ2) m2 (θ2'2 L2 + θ1'2 L1 cos(θ1 − θ2))
L1 (2 m1 + m2 − m2 cos(2 θ1 − 2 θ2))

with θ2 and θ2'2 being the only unknowns but I am not getting the results that are needed. Can someone please check if there are any mistakes in my equation.

NDSolve[{20.64*-Cos[
6.3 t] == ((-9.8*(1.61)*
Sin[.52*Sin [6.3 t]]) - (1.61*9.8*
Sin[Sin [6.3 t] - 2 Theta[t]] - (2*
Sin[Sin [6.3 t] -
Theta[t]])*1.61*((Theta'[t])^2 *0.48 + (3.21*
Cos[6.3 t])^2*.3*Cos[.52*Sin [6.3 t]] -
Theta[t])/(.30 (1.61 -
1.61*Cos[2*.52*Sin [6.3 t] - 2*Theta[t]])))),
Theta[0] == 10000}, Theta[t], {t, 0, 10}]

Thanks!
 
Physics news on Phys.org
It appears, at least with the version I am running, that the solver is running into limits on the number of steps to take trying to find a solution before it finishes.

By reducing the accuracy and precision demands greatly it is possible to get it to solve.

In[1]:= s=NDSolve[{20.64*-Cos[6.3 t]==((-9.8*(1.61)*Sin[.52*Sin[6.3 t]])-(1.61*9.8*Sin[Sin[6.3 t]-2 Theta[t]]-(2*Sin[Sin[6.3 t]-Theta[t]])*1.61*((Theta'[t])^2*0.48+(3.21*Cos[6.3 t])^2*.3*Cos[.52*Sin[6.3 t]]-Theta[t])/(.30 (1.61-1.61*Cos[2*.52*Sin[6.3 t]-2*Theta[t]])))),Theta[0]==10000},Theta[t],{t,0,10},
AccuracyGoal->1,PrecisionGoal->1]

Out[1]= {{Theta[t]->InterpolatingFunction[{{0.,10.}},<>][t]},{Theta[t]->InterpolatingFunction[{{0.,10.}},<>][t]}}

This should then show you one of the solutions:

In[2]:= ListPlot[Table[{j,First[First]/.t->j},{j,0,10,.1}]/.->[_,v_]->v]

And this should then show you the other solution.

In[3]:= ListPlot[Table[{j,First[Last]/.t->j},{j,0,10,.1}]/.Rule[_,v_]->v]

If you GENTLY increase the AccuracyGoal and PrecisionGoal you should start to see it produce something more like what the real solutions are, but by the time I get up to 4 I start getting complaints about a complex component being introduced, although the plot does start to look a little bit like a sine wave oscillating around 9993.

I used the ListPlot to look at these because my first few attempts at getting anything sensible to Plot directly from the InterpolatingFunction failed. You can bump down the step size in that ListPlot and see a little more detail.

Take a look at the results from the ListPlot s and see if this is anything like what your real system should be doing. If it is then this may be moving in the direction of getting you something useful. If so then you might look at Options[NDSolve] and use the help system to take a look at what each of those options do. Those will be used, in a way similar to how I used AccuracyGoal, to control the solver and get it to find a way to deliver the solution you desire.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K