Solving a system of equations fails

57 views
Skip to first unread message

Uwe Fechner

unread,
Sep 16, 2015, 11:49:59 AM9/16/15
to sympy
Hello,

I try to calculate the tangent of a circle. This is a quite simple system of equations (one is quadratic),
but sympy fails (empty solution set). Any idea why?

from __future__ import division
from sympy import *
from sympy.solvers import solve

init_printing(use_latex = True)
r, phi_0, phi_1, phi_2, beta_0, beta_1, beta_2= symbols('r phi_0, phi_1, phi_2, \
     beta_0, beta_1, beta_2')

if True:
    if True:
        phi_0 = 0
        beta_0 = 0
        phi_1 = 1.
        beta_1 = 1.
        r=1.
    eq1 = Eq((phi_2 - phi_1) * (phi_2 - phi_1) + (beta_2 - beta_1) * (beta_2 - beta_1) - r*r)
    eq2 = Eq((phi_2 - phi_0) * (phi_2 - phi_1) + (beta_2 - beta_0) * (beta_2 - beta_1))
    result = solve([eq1, eq2], phi_2)
    print result

The result is an empty list. Any idea, how to fix this?
Expected result: phi_2 = 1.


Any hints appreciated!

U. Fechner, TU Delft

Aaron Meurer

unread,
Sep 16, 2015, 6:07:14 PM9/16/15
to sy...@googlegroups.com
If you don't tell solve() that beta_2 is a parameter, it assumes that
it is a constant. It then returns no solutions because it solves eq1
and eq2 each for phi_2 and sees that they look different, because they
are only equal for certain values of beta_2 (at least, I'm fairly sure
this is what is happening).

You can get the solutions by telling solve that beta_2 is a parameter

In [14]: solve([eq1, eq2], [phi_2, beta_2])
Out[14]: [(0.0, 1.0), (1.0, 0.0)]

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+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/09115c90-e2b9-40e4-93e1-42e9696adc22%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Uwe Fechner

unread,
Sep 18, 2015, 4:34:52 AM9/18/15
to sympy
Thank you very much, that did the trick.

Uwe
Reply all
Reply to author
Forward
0 new messages