Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Program to solve coupled ODEs?

  1. Sep 3, 2015 #1
    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
     
  2. jcsd
  3. Sep 3, 2015 #2
    Mathematica
     
  4. Sep 3, 2015 #3
    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.
     
  5. Sep 3, 2015 #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.
     
  6. Sep 3, 2015 #5
    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: Sep 3, 2015
  7. Sep 3, 2015 #6
    Looks like it might be your use of brackets. If you are grouping for multiplication you must use parentheses.
     
  8. Sep 3, 2015 #7
    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
     
  9. Sep 4, 2015 #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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Program to solve coupled ODEs?
  1. A couple of questions (Replies: 6)

  2. Couple of questions (Replies: 11)

  3. Coupled motions (Replies: 0)

Loading...