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
|
#!/usr/bin/env python
"""Differentiation example
Demonstrates some differentiation operations.
"""
from sympy import pprint, Symbol
def main():
a = Symbol('a')
b = Symbol('b')
e = (a + 2*b)**5
print("\nExpression : ")
print()
pprint(e)
print("\n\nDifferentiating w.r.t. a:")
print()
pprint(e.diff(a))
print("\n\nDifferentiating w.r.t. b:")
print()
pprint(e.diff(b))
print("\n\nSecond derivative of the above result w.r.t. a:")
print()
pprint(e.diff(b).diff(a, 2))
print("\n\nExpanding the above result:")
print()
pprint(e.expand().diff(b).diff(a, 2))
print()
if __name__ == "__main__":
main()
|