首页 > 其他分享 >2-9

2-9

时间:2024-10-08 17:44:31浏览次数:5  
标签: 求解 equations variables solution 数值 Eq

from sympy import symbols, Eq, solve

定义未知数

x, y = symbols('x y')

定义非线性方程组

equations = (Eq(x**2 - y - x - 3, 0), Eq(x + 3*y - 2, 0))

求解符号解

symbolic_solution = solve(equations, (x, y))
print("符号解:", symbolic_solution)

数值解需要使用数值方法求解

from scipy.optimize import fsolve

定义非线性方程组的函数

def equations(variables):
x, y = variables
return [x**2 - y - x - 3, x + 3*y - 2]

初始猜测值

initial_guess = [1, 1]

求解数值解

numeric_solution = fsolve(equations, initial_guess)
print("数值解:", numeric_solution)

标签:,求解,equations,variables,solution,数值,Eq
From: https://www.cnblogs.com/gunpxjcwy/p/18452177

相关文章