OBJECTIVE: get variables in returned equation to synch with local
variables.

EXAMPLE OF PROBLEM

Let's say I want to find where a parabola intersects with a line.

I create variables and a parabola equation

>>> var('x y')
(x, y)
>>> p=2*x**2-3*x+4

I create a line that I know passes through two points on that parabola
using geometry:

>>> l=Line(Point(-2, p.subs(x, -2)), Point(2, p.subs(x, 2)))

I get the equation of the line in terms of x and y:

>>> line = l.equation(); line
-48 + 4*y + 12*x

The problem is, though "in" thinks x (and y are in the equation)...

>>> x in line
True

the local variables that I created above are not actually in there:

>>> x in line.atoms(), y in line.atoms()
(False, False)

So I can't solve that line for y and use the x-dependent part along
with the parabola I defined to find the intersection, e.g.

>>> solve(line, y)
[]

So I want a way to, by name, connect the variables in line to my local
variables. I use this (which works) but I am looking for a way to pass
something from which the variables in the local context can be found.

def remap(eq, *locals):
        d = dict((s.name, s) for s in eq.atoms(Symbol))
        l = dict((s.name, s) for s in locals)
        for n,s in d.items():
                eq=eq.subs(d[n], l[n])
        return eq

>>> line = remap(line, x, y)
>>> x in line.atoms()
True
>>> solve(line, y)
[12 - 3*x]

>>> print solve(Eq(p, solve(line, y)[0]), x)
[2, -2]

Does anyone have suggestions on how to better accomplish that
remapping? Perhaps the equation() should take two variables rather
than two strings. Right now it essentiall creates x as
Symbol(given_string_for_x, real=True).

/c

-- 
You received this message because you are subscribed to the Google Groups 
"sympy-patches" group.
To post to this group, send email to sympy-patc...@googlegroups.com.
To unsubscribe from this group, send email to 
sympy-patches+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy-patches?hl=en.

Reply via email to