How to specify proprties of a constant

19 views
Skip to first unread message

maarte...@knmi.nl

unread,
Sep 22, 2016, 12:21:34 PM9/22/16
to sympy
Hi,

I'm creating an example for using SymPy, using the good old harmonic oscillator as an example:

import sympy
s
= sympy.Function("s")
t
, zeta, m, k = sympy.symbols("t, zeta, m, kappa")
expr
= sympy.Eq(m*s(t).diff(t, t), -k*s(t))
sympy
.dsolve(expr, s(t), ics={s(t).diff(t,1).subs(t,0):0})


The latex form of the output is:

s{\left (t \right )} = 
C_{1} e^{- t \sqrt{- \frac{\kappa}{m}}} +
C_{2} e^{t \sqrt{- \frac{\kappa}{m}}}


This gives a nice and generic result, but a bit too generic to my taste. For instance the constants m and k are both positive, and with that knowledge it is easy to express teh result using sine and cosine functions (and with the constraint: only a cosine).

How do I tell SymPy that m and k are > 0?

Best,

Maarten

Aaron Meurer

unread,
Sep 22, 2016, 12:24:39 PM9/22/16
to sy...@googlegroups.com
Use 

m, k = symbols("m, kappa", positive=True)

Aaron Meurer 
--
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+unsubscribe@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/52da57bb-dffe-4a98-b024-d0a7c8c99e98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

maarte...@knmi.nl

unread,
Sep 23, 2016, 6:05:31 AM9/23/16
to sympy

On Thursday, September 22, 2016 at 6:24:39 PM UTC+2, Aaron Meurer wrote:
Use 

m, k = symbols("m, kappa", positive=True)

Thank you.
Reply all
Reply to author
Forward
0 new messages