Incorrect result from solve function

59 views
Skip to first unread message

David Colson

unread,
Mar 2, 2016, 3:01:51 PM3/2/16
to sympy
Hello,

This issue has bothered me for a few days I can seem to see what's wrong. So I resorted to asking for help.

I'm trying to derive the equations of motion for a double pendulum system using Lagrangian mechanics. It involves some unpleasant algebra to solve and I thought sympy would be ideal. Sympy worked perfectly right up until the end. I have two dependant second order differential equations, the idea being to substitute one into the other and solve for the second derivative term. That way I obtain two differential equations that are not linked by a second order term so I can solve it with a numerical solver.

But in this substitution and solving step the result being given by sympy is wrong. I've gone over it countless times, and compared against the known solution, but it's wrong, and I can't see why. I've remembered to subtract the term on the right hand side of the equation so I'm solving for something equal to zero. But still the answer is wrong. I don't believe it possible that sympy is wrong, but I cannot see where I am making a mistake. I'd appreciate it if someone else took a glance at it.


Thank you kindly for any help!

David.

Ondřej Čertík

unread,
Mar 2, 2016, 3:07:23 PM3/2/16
to sympy
Hi David,

On Wed, Mar 2, 2016 at 12:50 PM, David Colson <scal...@gmail.com> wrote:
> Hello,
>
> This issue has bothered me for a few days I can seem to see what's wrong. So
> I resorted to asking for help.
>
> I'm trying to derive the equations of motion for a double pendulum system
> using Lagrangian mechanics. It involves some unpleasant algebra to solve and
> I thought sympy would be ideal. Sympy worked perfectly right up until the
> end. I have two dependant second order differential equations, the idea
> being to substitute one into the other and solve for the second derivative
> term. That way I obtain two differential equations that are not linked by a
> second order term so I can solve it with a numerical solver.
>
> But in this substitution and solving step the result being given by sympy is
> wrong. I've gone over it countless times, and compared against the known
> solution, but it's wrong, and I can't see why. I've remembered to subtract
> the term on the right hand side of the equation so I'm solving for something
> equal to zero. But still the answer is wrong. I don't believe it possible
> that sympy is wrong, but I cannot see where I am making a mistake. I'd
> appreciate it if someone else took a glance at it.

It's definitely possible that SymPy is wrong. We need to investigate
this further to see if it's a bug in sympy or in your derivation.

In general SymPy is pretty well tested, but once in a while you can find a bug.

> Here is an ipython notebook containing the entire derivation and solution.
> I've left some notes explaining where it goes wrong.

Here is a view of your notebook:

http://nbviewer.jupyter.org/urls/dl.dropboxusercontent.com/u/53792213/Double%20Pendulum%20Solution.ipynb

Unfortunately I don't have time right now to look into it. You might
also be interested in trying pydy.org, which uses sympy and it has a
double pendulum example:

http://www.pydy.org/examples/double_pendulum.html

Ondrej

>
> Thank you kindly for any help!
>
> David.
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/09bfc087-b6c1-49db-9ab7-3ae1bd610667%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Jason Moore

unread,
Mar 2, 2016, 5:41:19 PM3/2/16
to sy...@googlegroups.com
I just ran your notebook and added this line to the bottom:

trigsimp(theta1dotdot_alt - theta1dotdot[0])

This returns zero, which means the solution you derive is equivalent to the the version you provide.

I'd recommend the sympy.physics.mechanics package if you'd like to have more tools to work with derivations of multibody systems.

David Colson

unread,
Mar 2, 2016, 6:03:30 PM3/2/16
to sympy
Hi Jason,

Yea it appears I had it correct all along. I wasn't aware of the trigsimp function so I never thought the two equations matched correctly. Thank you for your help it's much appreciated.

I'll check out that mechanics package!

Thanks again!
David
Reply all
Reply to author
Forward
0 new messages