Comment #1 on issue 2033 by smichr: solve should be able to handle rational
function systems
http://code.google.com/p/sympy/issues/detail?id=2033
This is a direction I would go:
def ssolve(eqs, syms):
'''Rather than trying to solve all equations at once as a linear
system, solve them sequentially. Search through all possible
combinations of symbols and equations for the combination that
works. e.g.
solve([exp(x)-sin(y), 1/y-3], [x,y]) fails since neither of these
is linear as written. However, if the 2nd eq is solved for y and
the first is solved for x, a solution set is obtained.
It is possible that more than one solution will be obtained for
a given symbol:
solve([exp(x)-sin(y), x**2+y**2-3], [x,y]) fails because it is not
linear, but the 2nd equation can be solved for x or y to give two
solutions and then these two substituted into equation 1's solution
for the other variable. Unfortunately in this caea there is no solution
for x and y since if you substitute a value of x = f(y) from the
second into the first you cannot solve the first for y.apart
Part II of this routine will try to find the combination that works.
'''
from sympy.utilities.iterables import cartes
failed = {}
# each equation has its own set of symbols that are of interest
# one might not have all symbols in all equations
stry = [set(syms).intersection(eq.atoms(Symbol)) for eq in eqs]
# hopefully one of the combinations will work
for symsi in cartes(*stry):
# if it didn't work in the past or
# if we already have a solution for si or
# this isn't a full spanning set, skip it
if len(set(symsi)) != len(eqs):
continue
eq_s = zip(eqs, symsi)
succeed = {}
if any(eqi in failed and si in failed[eqi] or
si in succeed.keys() for eqi,si in eq_s):
continue
for eqi,si in eq_s:
try:
succeed[si] = solve(eqi, si)
except:
failed.setdefault(eqi, []).append(si)
break
else:
yield succeed
list(ssolve([exp(x)-sin(y), x**2+y**2-3], [x,y]))
[{x: [log(sin(y))], y: [(3 - x**2)**(1/2), -(3 - x**2)**(1/2)]}, {x: [(3 -
y**2)**(1/2), -(3 - y**2)**(1/2)], y: [asin(exp(x))]}]
list(ssolve([exp(x)-sin(y), 1/y-3], [x,y]))
[{x: [log(sin(y))], y: [1/3]}]
list(ssolve([r - x**2 - y**2, tan(t) - y/x], [x, y]))
[{x: [(y - y**2)**(1/2), -(y - y**2)**(1/2)], y: [x*tan(t)]}, {x:
[y/tan(t)], y: [1/2 - (1 - 4*x**2)**(1/2)/2, 1/2 + (1 - 4*x**2)**(1/2)/2]}]
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" 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-issues?hl=en.