Home | Python | IPython | * IPython: Math Processor 2: Installation 3: Getting Started 4: Equation Processing 5: Equation Solving 6: Normal Distribution 7: Differential Equations 8: Fourier Transforms 9: Tips & Tricks   Share This Page
IPython: Math Processor
A tool that manipulates mathematics as a word processor manipulates words

Differential Equations

(double-click any word to see its definition)

Differential Equations

Differential equations play an important part in modern science, physics in particular. It is sometimes said that modern physical theory is represented by a large set of field-tested differential equations. But until the availability of cheap computer power, processing and experimenting with differential equations remained out of reach of any but the most skilled mathematicians. Environments like IPython change that — they make the study of differential equations, and of their subject matter, much more accessible.

A differential equation is a series of statements about an unknown function including derivatives of that function. For example, for a physical system in which the rate of change is proportional to the remaining difference between two quantities, we might write these terms:

(1) $\displaystyle k \, u'(t) + u(t) = 0$

(2) $\displaystyle u(0) = 1$

Where:

• $t$ = time.
• $u(t)$ = an unknown function accepting a time argument.
• $u'(t)$ = the first derivative of $u(t)$ with respect to time.
• $k$ = a constant describing a rate of change.
• $u(0)$ = the value of the unknown function at time zero.

As it happens, these terms describe a very common differential equation that models many natural systems — current flow in electronic circuits, gas flow between pressurized reservoirs, water flow between bodies of water, and many other examples. Let's use IPython to find the unknown equation:

Some notes on this solution:

IPython Entry Comment
u = Function("u")(t) Declares that an unknown function u is a function of t.
de = Eq(u+u.diff(t) * k) Declares the terms of the differential equation, implicitly equal to zero.
des = dsolve(de,u) Call sympy.dsolve() to produce a solution for u(t).
des = des.subs(C1,0) Eliminate an unnecessary integration constant.
f = Lambda((t,k,a,b),(a-b) * des.rhs + b) Create a more useful form of the result with initial (a) and final (b) value definitions.

In the above notebook display, notice the notation IPython uses to describe the differential equation terms:

(3) $\displaystyle k \frac{\partial}{\partial t} \operatorname{u}{\left (t \right )} + \operatorname{u}{\left (t \right )} = 0$

A number of computer math programs, and workers, use a different convention to describe a derivative:

(4) $\displaystyle k \operatorname{u}'{\left (t \right )} + \operatorname{u}{\left (t \right )} = 0$

But the reader should understand that these different ways to describe a derivative are equivalent and only represent a matter of taste:

(5) First derivative: $\displaystyle \operatorname{u}'{\left (t \right )} = \frac{\partial}{\partial t} \operatorname{u}{\left (t \right )}$

(6) Second derivative: $\displaystyle \operatorname{u}''{\left (t \right )} = \frac{\partial^2}{\partial t^2} \operatorname{u}{\left (t \right )}$

This notation issue is more fully described here.

The result of the above process must be rewritten post hoc to accommodate initial and final values because at the time of writing, the sympy dsolve() function doesn't accept initial condition/value entries.

The final form of the result:

(7) $\large f(t,k,a,b) = b + \left(a - b\right) e^{- \frac{t}{k}}$

Is able to model many natural processes in science and technology. As one example, the function can model an electronic resistor-capacitor (R-C) circuit's values over time:

The reader may notice that these examples acquire function definitions directly from calculation outcomes, rather than by rewriting a result. This has many advantages, not least of which is the avoidance of typographical errors. But the symbolic Python scheme retains abstract definitions to the maximum practical degree. For example, we have defined this function:

(8) $\large f(t,k,a,b) = b + \left(a - b\right) e^{- \frac{t}{k}}$

But because of how sympy manages symbols, we can express the function differently by providing different arguments:

var('t x y r c')
display(f(t,r * c,x,y))

$\large y + \left(x - y\right) e^{- \frac{t}{c r}}$

This outcome results from symbolic Python's design, which favors replacing one symbol with another over abandoning a symbol or replacing it with a numerical value.

To navigate this article set, use the arrows and drop-down lists at the top and bottom of each page.

 Home | Python | IPython | * IPython: Math Processor 2: Installation 3: Getting Started 4: Equation Processing 5: Equation Solving 6: Normal Distribution 7: Differential Equations 8: Fourier Transforms 9: Tips & Tricks   Share This Page