Python求解多元非线性方程组

使用sympy模块:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ sympy

案例

import sympy


def solve_test():
    a, b = sympy.symbols('a b')  # 两个未知数
    eq1 = a + 2 * b  # 等式一: a+2b = 0
    eq2 = a * 4 - 5 + b  # 等式二:4a-5+b = 0
    sol = sympy.solve((eq1, eq2), (a, b))  # 求解
    return sol


if __name__ == '__main__':
    solve_value = solve_test()
    print(solve_value) # {a: 10/7, b: -5/7}

你可能感兴趣的:(python,sympy)