Solve non-dimensionalized spring pendulum system on python

Click For Summary
SUMMARY

The discussion focuses on solving a non-dimensionalized spring pendulum system using Python 2.7 and the odeint function from the SciPy library. The user presents the governing differential equations for both the x and y directions, which include a non-dimensional parameter σ. A solution approach is provided, demonstrating how to modify the right-hand side function to incorporate both x and y vectors, allowing for simultaneous computation of their dynamics.

PREREQUISITES
  • Understanding of differential equations, specifically non-dimensionalization
  • Familiarity with Python 2.7 programming
  • Knowledge of the SciPy library, particularly the odeint function
  • Basic concepts of vector calculus and dynamics
NEXT STEPS
  • Explore advanced features of SciPy's odeint for solving complex systems
  • Learn about non-dimensional analysis in mechanical systems
  • Investigate numerical stability and error analysis in ODE solvers
  • Study the implementation of multi-dimensional systems in Python
USEFUL FOR

Students and researchers in physics and engineering, particularly those working on dynamic systems and numerical methods for solving differential equations.

gothloli
Messages
37
Reaction score
0

Homework Statement


I'm supposed to solve the spring pendulum numerically on python 2.7, using odeint. The system is supposed to solved for the y -direction and the x-direction in terms of time. In class we did this for pendulum DE, but that only had x as the dependent variable, this system has two.

Homework Equations


These are the non-dimensionalized De's I get
\frac{d^{2}Y}{d\tau^{2}} = -1+\frac{(1-Y)}{\sigma}-\frac{(1-\sigma)(1-Y)}{\sigma\sqrt{X^{2}+(1-Y)^{2}}}

and
\frac{d^{2}X}{d\tau^{2}}=-\frac{X}{\sigma}+\frac{(1-\sigma)X}{\sigma\sqrt{X^{2}+(1-Y)^{2}}}.
Where σ is the non-dimensional parameter

The Attempt at a Solution


def rhs(xvector,t):

x1dot=xvector[1]
x2dot=xvector[3]
x3dot=yvector[0]
x4dot=(-xvector[1]/sigma)+((1-sigma)*xvector[0])/(sigma*sqrt((xvector[0])**2+(1-yvector[0])**2))

return [x1dot,x2dot,x3dot,x4dot]

This is the beginning of the code, but I don't know how to include the y vector into this function?
 
Last edited:
Technology news on Phys.org


I understand your struggle with using odeint to solve a spring pendulum with two dependent variables. The first step in solving this problem is to make sure that your equations are correctly non-dimensionalized, as this can affect the behavior of the system. From your homework equations, it looks like you have correctly non-dimensionalized the equations.

To include the y vector into your function, you can simply add it as another input to the function. Your function will then take in both the x and y vectors, and you can use them in your equations accordingly. Your code would look something like this:

def rhs(xvector, yvector, t):
x1dot = xvector[1]
x2dot = xvector[3]
y1dot = yvector[1]
y2dot = (-yvector[1]/sigma) + ((1-sigma)*yvector[0])/(sigma*sqrt((xvector[0])**2+(1-yvector[0])**2))

return [x1dot, x2dot, y1dot, y2dot]

This way, you can solve for both the x and y directions simultaneously. I hope this helps and good luck with your assignment!
 

Similar threads

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