Program to solve coupled ODEs?

AI Thread Summary
The discussion revolves around using Mathematica to solve coupled second-order non-linear ordinary differential equations (ODEs) for a double pendulum system. The user initially struggled with the software but received guidance on proper syntax for inputting equations. After resolving some issues, they managed to obtain a solution, albeit only accurate for a limited time due to the equations' complexity. Suggestions were made to explore small angle approximations to validate the numerical solution against exact solutions. Overall, the conversation highlights the challenges and solutions in applying Mathematica for complex mechanical systems.
tomdodd4598
Messages
137
Reaction score
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
Mathematica
 
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.
 
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.
 
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:
Looks like it might be your use of brackets. If you are grouping for multiplication you must use parentheses.
 
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
 
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.
 
Back
Top