File: differential_equations.py

package info (click to toggle)
sympy 0.7.5-3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 26,576 kB
  • ctags: 27,948
  • sloc: python: 213,240; xml: 359; makefile: 117; sh: 53; lisp: 4
file content (27 lines) | stat: -rwxr-xr-x 583 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/env python

"""Differential equations example

Demonstrates solving 1st and 2nd degree linear ordinary differential
equations.
"""

from sympy import dsolve, Eq, Function, sin, Symbol


def main():
    x = Symbol("x")
    f = Function("f")

    eq = Eq(f(x).diff(x), f(x))
    print("Solution for ", eq, " : ", dsolve(eq, f(x)))

    eq = Eq(f(x).diff(x, 2), -f(x))
    print("Solution for ", eq, " : ", dsolve(eq, f(x)))

    eq = Eq(x**2*f(x).diff(x), -3*x*f(x) + sin(x)/x)
    print("Solution for ", eq, " : ", dsolve(eq, f(x)))


if __name__ == "__main__":
    main()