On Wed, Nov 16, 2011 at 1:04 PM, Daniel <[email protected]> wrote:
> I'm trying to write a program to enhance my understanding of a
> classical physics class that I am taking. I'm using vpython to create
> free body diagrams and to animate kinetic motion from forces that are
> described in a class I wrote. I want to turn this into more of a
> general purpose solver by using sympy to solve symbolically instead of
> relying on the user to enter in the magnitude and angle of each force
> vector.
>
> I'm still getting accustomed to using sympy, but I keep running into a
> problem. I can solve symbolically for one equation as in:
>
> a = Symbol('a')
> v = Symbol('v')
> t = Symbol('t')
> foo = solve(a*t+v,v) # v in terms of t and a
>
> but I am unable to use that symbolic solution foo in another
> equation. For example:
>
> solve(foo/t,a)
If you look at the docstring for solve (try typing help(solve)
interactively) you will see the variety of ways values are returned.
Basically, if you solve one equation you get a list of answer(s). So
if you want a particular solution, you have to tell python which one;
if there is only one solution then the one you want is foo[0]
>>> var('a t v')
(a, t, v)
>>> solve(a*t+v,v)
[-a*t]
>>> foo = _
>>> solve(foo[0]/t,a)
[0]
If you want to solve a more than one equation you will need to send
them as a list and you will get a dictionary returned if it is linear,
otherwise a list of tuples:
>>> solve([x + y - 3, x - y - 1], [x, y])
{x: 2, y: 1}
>>> solve([x + y**2 - 3, x - y - 1], [x, y])
[(-1, -2), (2, 1)]
>>> solve([x + y**2 - 3, x - y - 1])
[{x: -1, y: -2}, {x: 2, y: 1}]
>>> solve([x + y - 3, x - y - 1])
{x: 2, y: 1}
Notice that the symbols you are solving for can be left out (if there
are as many eqs as unknowns). If you run into other problems, let us
know.
/chris
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.