<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "AMS" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js"]
}
});
</script>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Fix slow MathJax rendering in IE8 -->
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<!-- This is a demo of a blog shown on -->
<!-- <a href="http://doconce.blogspot.com"><tt>http://doconce.blogspot.com</tt></a> -->
<!-- <a href="http://doconce.shoutwiki.com/wiki/Doconce_demo"><tt>http://doconce.shoutwiki.com/wiki/Doconce_demo</tt></a> -->
<!-- <a href="http://doconcedemo.jumpwiki.com/wiki/First_demo"><tt>http://doconcedemo.jumpwiki.com/wiki/First_demo</tt></a> -->
<p>
Here is some simple mathematics:
<p>
$$
\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}
$$
which can be implemented in a computer code:
<p>
<!-- code typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">f</span>(x):
<span style="color: #BA2121; font-style: italic">"""Runge's function."""</span>
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #666666">1/</span>(<span style="color: #666666">1</span> <span style="color: #666666">+</span> x<span style="color: #666666">**2</span>)
<span style="color: #408080; font-style: italic"># Plot f</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
xcoor <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(<span style="color: #666666">-3</span>, <span style="color: #666666">3</span>, <span style="color: #666666">101</span>)
ycoor <span style="color: #666666">=</span> f(xcoor)
plt<span style="color: #666666">.</span>plot(xcoor, ycoor)
plt<span style="color: #666666">.</span>savefig(<span style="color: #BA2121">'f_plot.png'</span>)
<span style="color: #408080; font-style: italic"># Compute f'(x) symbolically and make a Python function out of it</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">sympy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">sm</span>
x <span style="color: #666666">=</span> sm<span style="color: #666666">.</span>Symbol(<span style="color: #BA2121">'x'</span>)
f_expr <span style="color: #666666">=</span> f(x)
<span style="color: #008000; font-weight: bold">print</span> f_expr
df_expr <span style="color: #666666">=</span> sm<span style="color: #666666">.</span>diff(f_expr, x)
<span style="color: #008000; font-weight: bold">print</span> df_expr
df <span style="color: #666666">=</span> sm<span style="color: #666666">.</span>lambdify(x, df_expr) <span style="color: #408080; font-style: italic"># turn expression into Python function</span>
<span style="color: #408080; font-style: italic"># Plot f'(x)</span>
plt<span style="color: #666666">.</span>figure()
plt<span style="color: #666666">.</span>plot(xcoor, df(xcoor))
plt<span style="color: #666666">.</span>savefig(<span style="color: #BA2121">'df_plot.png'</span>)
plt<span style="color: #666666">.</span>show()
</pre></div>
<p>
A plot of the function \( f(x) \)
defined in \eqref{eq:f}
appears below.
<p>
<center><p><img src="https://doconce.googlecode.com/hg/doc/blog/f_plot.png" align="bottom" width=400></p></center>
<p>
Here is the derivative \( f'(x) \) (with figure caption and label, which enables
referring to the figure later):
<p>
<center> <! -- figure -->
<hr class="figure">
<center><p class="caption">Figure 1: The derivative of Runge's function. <a name="fig:Runge:dfdx"></a> </p></center>
<p><img src="https://doconce.googlecode.com/hg/doc/blog/df_plot.png" align="bottom" width=400></p>
</center>
<p>
Movies can also be embedded:
<p>
<iframe width="420" height="315" src="http://www.youtube.com/embed/75Ju0eM5T2c" frameborder="0" allowfullscreen></iframe>
<p>
The elements above are generated by the following
<a href="http://code.google.com/p/doconce">Doconce</a> code.
<p>
<!-- code typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%">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)$
defined in \eqref{eq:f}
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]
</pre></div>
<p>
<table width="95%" border="0">
<tr>
<td width="25" align="center" valign="top">
<img src="https://doconce.googlecode.com/hg/bundled/html_images/lyx_notice.png" hspace="5" alt="Notice"></td>
<th align="left" valign="middle"><b>Notice</b></th>
</tr>
<tr>
<td> </td>
<td align="left" valign="top">
<p><p>
<ol>
<li> There must be no title, author, or date in the document.</li>
<li> If the Doconce code above is stored in a file
<a href="https://doconce.googlecode.com/hg/doc/blog/demo.do.txt.html"><tt>demo.do.txt</tt></a>, run
<tt>doconce format html demo</tt> to produce the HTML code, stored in
<a href="https://doconce.googlecode.com/hg/doc/blog/demo.html.html"><tt>demo.html</tt></a>.</li>
<li> Copy the text in <tt>demo.html</tt> into the blog text area on
<a href="http://doconce.blogspot.com"><tt>http://doconce.blogspot.com</tt></a> site, , using <em>HTML</em> mode.</li>
<li> Remember to first choose the <em>HTML-code</em> tab (and not just <em>Write</em>)
and to place the copied text between the <tt>div</tt> tags.</li>
</ol></p>
</td>
</tr>
</table>