0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

「sympyのEq」を調べた。

Last updated at Posted at 2023-09-06

DOC

sympy.solvers.solvers.solve(f, *symbols, **flags)
Algebraically solves equations and systems of equations.
https://docs.sympy.org/latest/modules/solvers/solvers.html#sympy.solvers.solvers.solve

Eqにsubs

from sympy import *
var('m,n,a,b',real=True)
eq1=Eq(m,n)                     ;print("#",eq1)
eq1=Eq(m,n).subs({m:2,n:4})     ;print("#",eq1)
eq1=Eq(m+a,n+b).subs({m:2,n:4}) ;print("#",eq1)
# Eq(m, n)
# False
# Eq(a + 2, b + 4)

Eqに*2

できませんでした。

from sympy import *
var('m,n,a,b',real=True)
eq1=Eq(m,n)                     ;print("#",eq1)
eq1=Eq(m,n)*2                   ;print("#",eq1)
# Eq(m, n)
# TypeError: unsupported operand type(s) for *: 'Equality' and 'int'

??? 他にいい方法がありますか???
??? ユーザー定義関数がありますか 汎用性があると助かります。???

from sympy import *
var('m,n,a,b',real=True)
eq1=Eq(m,n)                     ;print("#",eq1)
eq1=Eq(eq1.lhs*2,eq1.rhs*2)     ;print("#",eq1)
# Eq(m, n)
# Eq(2*m, 2*n)

=0

(参考) 以下のコメント欄

from sympy import *
var('a,b,x',real=True)
print("#",solve( Eq(a*x+b,0),x ) )
print("#",solve(    a*x+b   ,x ) )
print("#",solve(    a*x+b      ) )
# [-b/a]
# [-b/a]
# [{a: -b/x}]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?