Program to solve coupled ODEs?

In summary, the program was able to solve the equations for 1.6 seconds, but it did not match the exact solution.
  • #1
tomdodd4598
138
13
Hi there,

I have been using Leonard Susskind's lectures on classical mechanics to learn about Lagrangians and Hamiltonians, and decided to try to create a Lagrangian for the double pendulum and another pendulum-related system. I found the equations of motion, but they were unlike any differential equations I had ever seen before. I found out that, for each system, I had a pair of coupled second-order non-linear ODEs.

I have had no luck trying to find a program which can numerically solve these coupled ODEs. If anyone knows of such a program, I would love to know about it.

Thanks in advance
 
Physics news on Phys.org
  • #2
Mathematica
 
  • #3
brainpushups said:
Mathematica
I thought of Mathematica, but I wasn't aware it could solve problems such as this - thanks. As someone who is looking to get Mathematica anyway, which version should I go for? I will want to be able to solve problems such as this, but I am not sure which type of Mathematica is the cheapest that can.
 
  • #4
I don't think there is an actual difference between any of the versions (except the price - student and educator licenses are significantly less than the professional license if I recall...). If you are interested in purchasing a license I would just contact their customer service directly to talk about options. I've been quite happy with their service.
 
  • #5
brainpushups said:
I don't think there is an actual difference between any of the versions (except the price - student and educator licenses are significantly less than the professional license if I recall...). If you are interested in purchasing a license I would just contact their customer service directly to talk about options. I've been quite happy with their service.

Turns out that a friend that lives close by has had it for ages... I'm now using his computer via TeamViewer :P

I inputted the following, long expression, asking the program to solve the two equations:
EDIT: All of the sines and cosines are capitalised contrary to what's pasted in the spoiler.
s = NDSolve[{θ''[t] + φ'[t]*sin[φ[t]]*[cos[θ[t]]*cos[t] + sin[θ[t]]*sin[t]] + cos[φ[t]]*[θ'[t]*sin[θ[t]]*cos[t] + cos[θ[t]]*sin[t] - θ'[t]*cos[θ[t]]*sin[t] - sin[θ[t]]*cos[t]] == [φ'[t]*sin[φ[t]]*[cos[θ[t]]*cos[t] + sin[θ[t]]*sin[t]] - θ'[t]*cos[φ[t]]*[cos[θ[t]]*sin[t] - sin[θ[t]]*cos[t]]] + [φ'[t]^2]*cos[θ[t]]*sin[θ[t]] - 9.81*sin[θ[t]], φ'[t]*cos[φ[t]]*[sin[θ[t]]*cos[t] - cos[θ[t]]*sin[t]] + sin[φ[t]]*[θ'[t]*cos[θ[t]]*cos[t] - sin[θ[t]]*sin[t] + θ'[t]*sin[θ[t]]*sin[t] - cos[θ[t]]*cos[t]] + φ''[t]*[[sin[θ[t]]]^2] + 2*θ'[t]*φ'[t]*sin[θ[t]]*cos[θ[t]] == [[φ'[t]^2]*cos[φ[t]]*[sin[θ[t]]*cos[t] - cos[θ[t]]*sin[t]] + θ'[t]*φ'[t]*sin[φ[t]]*[cos[θ[t]]*cos[t] + sin[θ[t]]*sin[t]]], θ[0] == θ'[0] == φ[0] == φ'[0] == 0}, {θ, φ}, {t, 100}]
Plot[Evaluate[{θ[t], φ[t]} /. s], {t, 0, 100}, PlotStyle -> Automatic]

But I got the following error:
Syntax::sntxf: "φ'[t]*Sin[φ[t]]*" cannot be followed by "[Cos[θ[t]]*Cos[t]+Sin[θ[t]]*Sin[t]]".

Should I go to the Mathematica forums for this or is it something simple that I'm doing wrong?
 
Last edited:
  • #6
Looks like it might be your use of brackets. If you are grouping for multiplication you must use parentheses.
 
  • #7
brainpushups said:
Looks like it might be your use of brackets. If you are grouping for multiplication you must use parentheses.
Thank you! It's working now - sort of. It can only be solved accurately for 1.6 seconds... possibly just due to the equations' complexity.
4oBvGEk.png

Time t is on the x-axis, angle is on the y-axis, blue is θ, orange is φ, θ(0) = φ(0) = Pi/2, θ'(0) = φ'(0) = 0
 
  • #8
Hmm. I don't think there should be an issue with these particular coupled equations. I think I've used Mathematica in the past to do this same thing. Have you tried plotting the solution for a small angle where the small angle approximation would hold? You could compare the numerical solution to the exact solution in that case to make sure they match. When I have a chance today I'll try it myself - don't hold your breath though; its going to be a busy day and then I have company for the weekend.
 

1. What are coupled ODEs?

Coupled ODEs, or coupled ordinary differential equations, are a set of differential equations that are connected or interdependent. This means that the solution to one equation depends on the solution of another equation in the set.

2. Why is it important to solve coupled ODEs?

Coupled ODEs are commonly used in many scientific fields, such as physics, engineering, and biology, to model complex systems. Solving these equations allows scientists to understand and predict the behavior of these systems, which can have important practical applications.

3. What methods are used to solve coupled ODEs?

There are several methods for solving coupled ODEs, including numerical methods such as Euler's method, Runge-Kutta methods, and the finite difference method. Analytical methods such as separation of variables and the method of undetermined coefficients can also be used.

4. What are some challenges in solving coupled ODEs?

Solving coupled ODEs can be challenging due to the complexity of the equations and the interdependence between them. The initial conditions and boundary conditions also need to be carefully considered to obtain an accurate solution. Additionally, some systems may have non-linear or time-varying equations, which can make the solution more difficult.

5. What are some applications of coupled ODEs?

Coupled ODEs have a wide range of applications in various fields, including mechanics, electromagnetics, chemical reactions, population dynamics, and many others. They are also used in computer simulations and mathematical modeling to predict the behavior of systems in the real world.

Similar threads

Replies
28
Views
2K
Replies
6
Views
322
  • Differential Equations
Replies
3
Views
1K
Replies
7
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Science and Math Textbooks
Replies
12
Views
923
Replies
4
Views
1K
  • STEM Academic Advising
Replies
12
Views
1K
  • Programming and Computer Science
Replies
11
Views
3K
Replies
3
Views
2K
Back
Top