1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] fsolve (scipy) results in ValueError

Discussão em 'Python' iniciado por Stack, Setembro 12, 2024.

  1. Stack

    Stack Membro Participativo

    I am solving so called Blasius problem. I use the following code (copied from youtube lecutre https://www.youtube.com/watch?v=0L4h-hqZY2Y , timecode: 8:35):

    import numpy as np
    import matplotlib.pyplot as plt
    from scipy.integrate import odeint
    from scipy.optimize import fsolve
    from scipy.optimize import root
    from scipy.optimize import root_scalar

    eta = np.linspace(0, 10, 101)

    def blas(f, t):
    return (f[1], f[2], -(1/2)*f[2]*f[0])

    def blas0(x, ts):
    f0 = (0., 0., x)
    f = odeint(blas, f0, ts)
    return 1.-f[-1, 1]

    print(blas0(0.0, eta))
    print(blas0(0.1, eta))
    print(blas0(0.2, eta))
    print(blas0(0.332, eta))
    print(eta)

    xpp0 = fsolve(blas0, x0=0.1, args=(eta), xtol=1e-6)


    All the listed print-functions work well and print correct results. However, the function fsolve results in the following error:

    xpp0 = fsolve(blas0, x0=0.1, args=(eta), xtol=1e-6)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...
    ValueError: setting an array element with a sequence. The requested
    array has an inhomogeneous shape after 1 dimensions. The detected
    shape was (3,) + inhomogeneous part.

    • I tried to downgrade numpy and scipy packages.
    • I tried to add dtype=object in definition of eta.
    • I tried to use the function root instead of fsolve.
    • I tried to use other solutions found here (or in google).

    Neither of these methods work.

    The packages list:

    Package Version
    --------------- -----------
    contourpy 1.3.0
    CoolProp 6.6.0
    cycler 0.12.1
    fonttools 4.53.1
    kiwisolver 1.4.7
    matplotlib 3.9.2
    numpy 2.1.1
    packaging 24.1
    pandas 2.2.2
    pillow 10.4.0
    pip 24.2
    pyparsing 3.1.4
    PyQt6 6.7.1
    PyQt6-Qt6 6.7.2
    PyQt6_sip 13.8.0
    python-dateutil 2.9.0.post0
    pytz 2024.2
    scipy 1.14.1
    six 1.16.0
    tzdata 2024.1



    Does anybody knows what the problem can be?

    Continue reading...

Compartilhe esta Página