Import sympy

I had just had a look at sympy’s documentation and it provides good support for solving differential equations. Sample this . Solving a differential equation would be as simple as this

from sympy import Function , Derivative
from sympy.abc import x
f = Function('f')(x) #Creates a function f with respect to x
d = Derivative(f , x ) #Derivative of f wrt to x is stored in d
dsolve(d -f , f)

which gives   f(x) == C1*exp(x) as the ouput.

I also tried an example given in my book.

f = Function('f')(x) #Creates a function f with respect to x
d = Derivative(f , x , x)
d_ = Derivative(f , x)
dsolve(d - d_ - 2 * f - 4 * x * x)

which again gives me  f(x) == C1*exp(-x) + C2*exp(2*x) – 2*x**2 + 2*x – 3
as the required output.

P.S : I will try to fix a few bugs as soon as my exams get over , wish me luck.

Advertisements

2 comments

  1. Siddharth · · Reply

    wow awesome work man, you’ve really done a lot! hope your gsoc thing comes through!

    1. Thanks a lot for your wishes 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: