Program to solve coupled ODEs?

  • Context: Graduate 
  • Thread starter Thread starter tomdodd4598
  • Start date Start date
  • Tags Tags
    Coupled Odes Program
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
7 replies · 1K views
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.