First of all, I would suggest that you solve the system symbollically
and then substitute in values when you have a general solution.
Then, I would recommend some human insight to overcome the less-than-
optimal algorithm. :-)
eq1 = y*2/(e*2 - a) - (x + e)**2/a + 1
eq3 = y*2/(e*2 - c) - (x - e)**2/c + 1
The equations 1 and 3 are linear in y, quadratic in x. If you start by
solving eq1 for x and substituting into eq3 you get an equation of the
form A + B*y+sqrt(C+E*y) which master cannot solve (but is solvable on
my 1766 branch). That gets you off on the wrong path from start.
Instead, try something like the following:
>>> eq1
1 + 2*y/(-a + 2*e) - (e + x)**2/a
>>> eq3
1 + 2*y/(-c + 2*e) - (x - e)**2/c
Solve for the linear symbol:
>>> ys = solve(eq1, y)[0]
Substitute it into the other equation and keep only the numerator:
>>> eq3.subs(y, ys).as_numer_denom()[0].expand()
-4*a*c*e*x + c*a**2 - a*c**2 - 2*a*e*x**2 + 2*c*e*x**2 + 4*a*x*e**2 +
4*c*x*e**2 - 2*a*e**3 + 2*c*e**3
Solve it for x:
>>> xs=solve(_, x)
Define your replacements:
>>> r1=dict(
... a = ((a2 - c2)/2)**2,
... b = ((b2 - c2)/2)**2,
... c = ((d2 - c2)/2)**2,
... e = e2/2 )
>>> r2=dict(
... a2 = 5.10125066033543,
... b2 = 1.844025414703168,
... c2 = 2.303750131640994,
... d2 = 0,
... e2 = 3)
Now calculate your solutions and print the results, checking (to 3 sig
digits and dropping "small" residuals) that they satisfy the original
equation; also use a formatting string to make the numbers more tidy:
>>> for xi in xs:
... xi = xi.subs(r1).subs(r2).n()
... yi = ys.subs(r1).subs(r2).subs(x, xi).n()
... print ('%g '*2) % (xi, yi), [q.subs(r1).subs(r2).subs(dict(x=xi,
y=yi)).n(3, chop=True) for q in [eq1, eq3]]
...
7.20535 19.6876 [0, 0]
0.192176 0.241862 [0, 0]
So sympy can do it. The basics are there. You just have to help it.
Can you take the steps above and wrap those into your hyperplot? I
think you'll have a pretty robust routine if you do.
p.s. I think this is a good reminder that just because you have two
equations doesn't mean you should feed them to your CAS as "two
equations". It always pays to see what form they have. (Or conversely,
a CAS should not just blindly try to apply a general algorithm:
looking for linear symbols, getting rid of uneccessary terms, etc...
makes everything work better.)
--
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.