如何评估Sympy中的方程组?

时间:2022-08-26 12:37:34

I have the following system of equations

我有以下方程组

from sympy.abc import x,y,z
from sympy import solve, Eq

eqs = [Eq(x,y), Eq(y,z)]
result = solve(eqs, x)

now I want to be able to substitute a value for z and evaluate for x. how can I do that?

现在我希望能够替换z的值并为x求值。我怎样才能做到这一点?

1 个解决方案

#1


2  

You should include the two variables that you want to solve for after eqs and then proceed something as follows:

您应该在eqs之后包含要解决的两个变量,然后执行以下操作:

>>> result = solve(eqs, x, y)
>>> result[x].subs(z,42)
42

#1


2  

You should include the two variables that you want to solve for after eqs and then proceed something as follows:

您应该在eqs之后包含要解决的两个变量,然后执行以下操作:

>>> result = solve(eqs, x, y)
>>> result[x].subs(z,42)
42