[Python] Sympy, I can't solve an equation symbolically. It keeps trying to give real solutions

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

  1. Stack

    Stack Membro Participativo

    # Python 3.13
    # Used variables in question
    x = sym.Symbol("x")
    I1 = sym.Symbol("I₁")
    L = sym.Symbol("L")
    pi = sym.Symbol("Π")
    v2 = sym.Symbol("v2")
    P = sym.Symbol("P")
    E = sym.Symbol("E")

    I = I1 * (1 - x/L)

    # For the part a of the question one in Assignment 3.
    question_part = "a"
    if question_part == "a":
    func_v = (1 - sym.cos((pi*x)/(2*L))) * v2
    moment = P * L
    second_derivative_v = sym.diff(func_v, x, x)
    internal_strain_e_func = 0.5 * moment *second_derivative_v / (E * I)
    internal_strain_e = sym.integrate(internal_strain_e_func, (x, 0, L))
    external_e = P * v2
    tip_deflection_eq = sym.Eq(internal_strain_e, external_e)
    tip_deflection = sym.solve(tip_deflection_eq, v2, exclude=[I1, L, pi, P, E], implicit=True)
    sym.pprint(tip_deflection)


    Code above is for virtual displacement method for a beam deflection question. I can technically do it by hand however, I get a lot of questions that requires for me to solve integrals and I do make mistakes when I do it by hand. So in this one I thought I would do it by sympy and its okey up until the solve() method. For some reason I can't get a symbolically written solution for eq. The eq. I am trying to solve is:

    [​IMG]

    Edit: I am sorry everyone v2 is not supposed be a part in function v. The question gave it to me and I took it without thinking about it although I did learn stuff that I didn't know and would probably ask later so not much of a waste of your time. Thanks!

    Continue reading...

Compartilhe esta Página