1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#!/usr/bin/env python
"""Substitution example
Demonstrates substitution.
"""
import sympy
from sympy import pprint
def main():
x = sympy.Symbol('x')
y = sympy.Symbol('y')
e = 1/sympy.cos(x)
print()
pprint(e)
print('\n')
pprint(e.subs(sympy.cos(x), y))
print('\n')
pprint(e.subs(sympy.cos(x), y).subs(y, x**2))
e = 1/sympy.log(x)
e = e.subs(x, sympy.Float("2.71828"))
print('\n')
pprint(e)
print('\n')
pprint(e.evalf())
print()
a = sympy.Symbol('a')
b = sympy.Symbol('b')
e = a*2 + a**b/a
print('\n')
pprint(e)
a = 2
print('\n')
pprint(e.subs(a,8))
print()
if __name__ == "__main__":
main()
|