[Python] Find the equation of a line with sympy (y=mx+b)

Discussão em 'Python' iniciado por Stack, Março 1, 2025.

  1. Stack

    Stack Membro Participativo

    So I'm brushing up on my algebra and trying to learn sympy at the same time. Following an algebra tutorial on youtube, I'm at this point: [​IMG]

    I can't quite figure out how to isolate y

    What I've tried:

    p1 = sym.Point(-1, 1)
    m = -2
    eq = sym.Line(p1, slope=m).equation()
    eq


    returns: 2x + y + 1

    eq1 = sym.Eq(eq, 0)
    eq1


    Gives me: 2x + y + 1 = 0

    and..

    eq2 = sym.simplify(eq1)
    eq2


    Returns: 2x + y = -1

    ..but that's as close as I can get to isolating y (y = -2x - 1). I'm sure it's a simple answer but I've been searching on the intertubes for 2 days now without success. I've tried solve() and subs(), solve just returns an empty set and subs gives the original equation back. What am I doing wrong?

    Continue reading...

Compartilhe esta Página