本文整理汇总了Python中sympy.Eq.subs方法的典型用法代码示例。如果您正苦于以下问题:Python Eq.subs方法的具体用法?Python Eq.subs怎么用?Python Eq.subs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Eq
的用法示例。
在下文中一共展示了Eq.subs方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: solver
# 需要导入模块: from sympy import Eq [as 别名]
# 或者: from sympy.Eq import subs [as 别名]
def solver():
vals = {i: base_eq(i) for i in range(1, 12)}
coefficients = a, b, c, d, e, f, g, h, i, j, k = symbols(','.join('abcdefghijk'))
(x, n), lhs = symbols('x n'), a
answer = 1
for i, element in enumerate(coefficients[1:]):
lhs = lhs * n + element
equation = Eq(x, lhs)
results = solve([equation.subs(dict(n=t, x=vals[t])) for
t in range(1, i+3)])
results[n] = i + 3
if element != k:
answer += equation.subs(results).args[1]
return answer
示例2: solve_it
# 需要导入模块: from sympy import Eq [as 别名]
# 或者: from sympy.Eq import subs [as 别名]
def solve_it(eqn, knowns, x):
LHS, RHS = eqn['sympy'].split('=')
e = Eq(sympify(LHS), sympify(RHS))
voi = Symbol(x['symbol']) # upgrade sympy to 0.7.6 if this throws a unicode error
vals = dict()
for k in knowns:
vals[Symbol(k['symbol'])] = k['value']
for c in eqn['constants']:
vals[Symbol(c['symbol'])] = c['value']
answers = solve(e.subs(vals),voi)
answer = answers[0]
return answer.evalf()
示例3: test_equality_subs2
# 需要导入模块: from sympy import Eq [as 别名]
# 或者: from sympy.Eq import subs [as 别名]
def test_equality_subs2():
f = Function("f")
x = abc.x
eq = Eq(f(x)**2, 16)
assert bool(eq.subs(f(x), 3)) == False
assert bool(eq.subs(f(x), 4)) == True
示例4: test_equality_subs1
# 需要导入模块: from sympy import Eq [as 别名]
# 或者: from sympy.Eq import subs [as 别名]
def test_equality_subs1():
f = Function("f")
x = abc.x
eq = Eq(f(x)**2, x)
res = Eq(Integer(16), x)
assert eq.subs(f(x), 4) == res
示例5: test_equality_subs2
# 需要导入模块: from sympy import Eq [as 别名]
# 或者: from sympy.Eq import subs [as 别名]
def test_equality_subs2():
f = Function('f')
eq = Eq(f(x)**2, 16)
assert bool(eq.subs(f(x), 3)) is False
assert bool(eq.subs(f(x), 4)) is True
示例6: set_free_surface
# 需要导入模块: from sympy import Eq [as 别名]
# 或者: from sympy.Eq import subs [as 别名]
def set_free_surface(self, d, b, side, algo='robertsson'):
"""
set free surface boundary condition to boundary d, at index b
:param indices: list of indices, e.g. [t,x,y,z] for 3D
:param d: direction of the boundary surface normal
:param b: location of the boundary (index)
:param algo: which algorithm to use to compute ghost cells
algo == 'robertsson' [1]: setting all velocities at ghost cells to zero
algo == 'levander' [2]: only valid for 4th spatial order. using 2nd order FD approximation for velocities
side: lower boundary (0) or upper boundary (1)
e.g. set_free_surface([t,x,y,z],1,2,0)
set y-z plane at x=2 to be lower free surface
ghost cells are calculated using reflection of stress fields
store the code to populate ghost cells to self.bc
[1] Robertsson, Johan OA. "A numerical free-surface condition for elastic/viscoelastic finite-difference modeling in the presence of topography." Geophysics 61.6 (1996): 1921-1934.
[2] Levander, Alan R. "Fourth-order finite-difference P-SV seismograms." Geophysics 53.11 (1988): 1425-1436.
"""
idx = list(self.indices)
if d not in self.direction:
if (not algo == 'levander') or (not self.direction[0] == self.direction[1]):
# shear stress, e.g. Tyz no need to recalculate at x boundary (only depends on dV/dz and dW/dy)
self.bc[d][side] = []
return
else:
# normal stress, need to recalcuate Tyy, Tzz at x boundary
expr = self.dt
derivatives = get_all_objects(expr, DDerivative)
for deriv in derivatives:
if deriv.var == idx[d]:
# replacing dx at x boundary with dy, dz terms
expr2 = self.sfields[d].dt
deriv_0 = deriv
deriv_sub = solve(expr2, deriv)[0]
break
expr = expr.subs(deriv_0, deriv_sub)
derivatives = get_all_objects(expr, DDerivative)
# substitution dictionary
dict1 = {}
for deriv in derivatives:
dict1[deriv] = deriv.fd[4]
expr = expr.subs(dict1)
eq = Eq(self.d[0][1].fd[2], expr)
eq = eq.subs(idx[d], b)
t = idx[0]
idx[0] = t+hf
idx[d] = b
# eq = eq.subs(t, t+hf)
# idx[0] = t+1
# idx[d] = b
# solve for Txx(t+1/2)
lhs = self[idx]
rhs = solve(eq, lhs)[0]
rhs = self.align(rhs)
# change t+1/2 to t+1
lhs = lhs.subs(t, t+hf)
rhs = rhs.subs(t, t+hf)
eq2 = Eq(lhs, rhs)
self.bc[d][side] = [eq2]
return
# use anti-symmetry to ensure stress at boundary=0
# this applies for all algorithms
idx = list(self.indices) # ghost cell
idx2 = list(self.indices) # cell inside domain
if not self.staggered[d]:
# if not staggered, assign T[d]=0, assign T[d-1]=-T[d+1]
idx[d] = b
idx2[d] = b
eq1 = Eq(self[idx])
else:
# if staggered, assign T[d-1/2]=T[d+1/2], assign T[d-3/2]=T[d+3/2]
idx[d] = b - (1-side)
idx2[d] = idx[d] + (-1)**side
eq1 = Eq(self[idx], -self[idx2])
eq1 = eq1.subs(idx[0], idx[0]+1)
self.bc[d][side] = [eq1]
for depth in range(self.order[d]/2-1):
# populate ghost cells
idx[d] -= (-1)**side
idx2[d] += (-1)**side
eq = Eq(self[idx], -self[idx2])
# change t to t+1
eq = eq.subs(idx[0], idx[0]+1)
self.bc[d][side].append(eq)
示例7: solve_constants
# 需要导入模块: from sympy import Eq [as 别名]
# 或者: from sympy.Eq import subs [as 别名]
def solve_constants(eq, ics, d_ics):
udiff = Eq(d_ics[0][1], eq.rhs.diff(t))
system = [eq.subs(ics), udiff.subs(t, 0)]
consts = solve(system, [C1, C2])
return eq.subs(consts)
示例8: symbols
# 需要导入模块: from sympy import Eq [as 别名]
# 或者: from sympy.Eq import subs [as 别名]
from sympy import solve
from sympy import symbols
from sympy import Eq
from sympy import Rational
P, V, n, R, T = symbols('P V n R T')
igl = Eq(P * V, n * R * T)
values = {
R : 8.3144621,
T : 273,
P : 101300,
n : 1
}
answers = solve(igl.subs(values),V)
answer = answers[0]
print ""
print "The ideal gas law is ",latex(igl)
print ""
print "Where the gas constant R is {} in SI units".format(values[R])
print "Standard temperature is {} Kelvin, or 0 degrees Celsius".format(values[T])
print "Standard pressure is {} pascals, or 1 atm".format(values[P])
print ""
print "So, at standard temperature and pressure, one mole of an ideal gas"
print " occupies {} cubic meters of volume".format(answer)
print ""
示例9: dict
# 需要导入模块: from sympy import Eq [as 别名]
# 或者: from sympy.Eq import subs [as 别名]
print ""
print "How long does it take an object released from rest to fall five meters?"
print ""
values = dict()
values[d] = -5
values[v0] = 0
values[a] = -9.81
print "The parameters for this problem are:"
print ""
for param, value in values.iteritems():
print " {} = {}".format(param, value)
print ""
answers = solve(kin1.subs(values),t)
if answers[0] > 0:
answer = answers[0]
else:
answer = answers[1]
print "Therefore the time involved is {} seconds.".format(answer)
print ""
values[t] = answer
answers = solve(kin2.subs(values),v)
answer = answers[0]
print "And its final speed is {} m/s.".format(answer)
print ""
示例10: Symbol
# 需要导入模块: from sympy import Eq [as 别名]
# 或者: from sympy.Eq import subs [as 别名]
p_i = Symbol("p_i", positive=True)
V_i = Symbol("V_i", positive=True)
tau_i = Symbol("tau_i", positive=True)
N_i = Symbol("N_i", positive=True)
idealgaslaw_i = Eq( p_i*V_i, N_i*tau_i)
p_f = Symbol("p_f", positive=True)
V_f = Symbol("V_f", positive=True)
tau_f = Symbol("tau_f", positive=True)
idealgaslaw_f = Eq( p_f*V_f, N_i*tau_f)
adia_tV = Eq( tau_i*V_i**(gamma-1) , tau_f*V_f**(gamma-1) )
##############################
# (a)
##############################
roomtemp_K = KCconv.subs(T_C,20).rhs # room temperature in Kelvin
Prob0104ans = adia_tV.subs(gamma,1.4).subs(V_f,1).subs(V_i,15).subs(tau_i, roomtemp_K) # answer to Problem 4 of Chapter 1
Prob0104ans = N( Prob0104ans.lhs) # 866.016969686253 K
Prob0104ansC = solve( KCconv.subs( T_K, Prob0104ans), T_C )[0] # 592.866969686253 C
solve( FCconv.subs( T_C, Prob0104ansC ), T_F)[0] # 1099.16054543526 F
##############################
# (b)
##############################
15*( Prob0104ans / roomtemp_K )