Doconce demo page

Page last edited 4,118 days ago
From Doconce MediaWiki Demos
Jump to navigation Jump to search


Here is some simple mathematics:

<math>

\begin{align} f(x) &= \frac{1}{1 + x^2}, \\ f'(x) & =-\frac{2x}{(1+x^2)^2} \end{align} </math> which can be implemented in a computer code:

def f(x):
    """Runge's function."""
    return 1/(1 + x**2)

# Plot f
import matplotlib.pyplot as plt
import numpy as np
xcoor = np.linspace(-3, 3, 101)
ycoor = f(xcoor)
plt.plot(xcoor, ycoor)
plt.savefig('f_plot.png')

# Compute f'(x) symbolically and make a Python function out of it
import sympy as sm
x = sm.Symbol('x')
f_expr = f(x)
print f_expr
df_expr = sm.diff(f_expr, x)
print df_expr
df = sm.lambdify(x, df_expr)  # turn expression into Python function

# Plot f'(x)
plt.figure()
plt.plot(xcoor, df(xcoor))
plt.savefig('df_plot.png')
plt.show()

A plot of the function <math>f(x)</math> appears below.


f_plot.png


Here is the derivative <math>f'(x)</math> (with figure caption and label, which enables referring to the figure later):


df_plot.png
The derivative of Runge's function. (fig:Runge:dfdx)


Movies can also be embedded:

http://www.youtube.com/watch?v=75Ju0eM5T2c

The elements above are generated by the following Doconce code.

Here is some simple mathematics:

!bt
\begin{align}
f(x) &= \frac{1}{1 + x^2},
label{eq:f}\\
f'(x) & =-\frac{2x}{(1+x^2)^2}
label{eq:df}
\end{align}
!et
which can be implemented in a computer code:

@@@CODE Runges_func.py

A plot of the function $f(x)$
appears below.

FIGURE: [https://doconce.googlecode.com/hg/doc/blog/f_plot.png, width=400]

Here is the derivative $f'(x)$ (with figure caption and label, which enables
referring to the figure later):

FIGURE: [https://doconce.googlecode.com/hg/doc/blog/df_plot.png, width=400] The derivative of Runge's function. label{fig:Runge:dfdx}

Movies can also be embedded:

MOVIE: [http://www.youtube.com/watch?v=75Ju0eM5T2c]