/usr/share/doc/pyxplot/html/ex-calculus.html is in pyxplot-doc 0.8.4-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="generator" content="plasTeX" />
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
<title>PyXPlot Users' Guide: Numerical Integration and Differentiation</title>
<link href="sect0024.html" title="Solving Systems of Equations" rel="next" />
<link href="sec-pastable.html" title="Creating Pastable Text" rel="prev" />
<link href="sect0019.html" title="Performing Calculations" rel="up" />
<link rel="stylesheet" href="styles/styles.css" />
</head>
<body>
<div class="navigation">
<table cellspacing="2" cellpadding="0" width="100%">
<tr>
<td><a href="sec-pastable.html" title="Creating Pastable Text"><img alt="Previous: Creating Pastable Text" border="0" src="icons/previous.gif" width="32" height="32" /></a></td>
<td><a href="sect0019.html" title="Performing Calculations"><img alt="Up: Performing Calculations" border="0" src="icons/up.gif" width="32" height="32" /></a></td>
<td><a href="sect0024.html" title="Solving Systems of Equations"><img alt="Next: Solving Systems of Equations" border="0" src="icons/next.gif" width="32" height="32" /></a></td>
<td class="navtitle" align="center">PyXPlot Users' Guide</td>
<td><a href="index.html" title="Table of Contents"><img border="0" alt="" src="icons/contents.gif" width="32" height="32" /></a></td>
<td><a href="sect0255.html" title="Index"><img border="0" alt="" src="icons/index.gif" width="32" height="32" /></a></td>
<td><img border="0" alt="" src="icons/blank.gif" width="32" height="32" /></td>
</tr>
</table>
</div>
<div class="breadcrumbs">
<span>
<span>
<a href="index.html">PyXPlot Users' Guide</a> <b>:</b>
</span>
</span><span>
<span>
<a href="sect0001.html">Introduction to PyXPlot</a> <b>:</b>
</span>
</span><span>
<span>
<a href="sect0019.html">Performing Calculations</a> <b>:</b>
</span>
</span><span>
<span>
<b class="current">Numerical Integration and Differentiation</b>
</span>
</span>
<hr />
</div>
<div><h1 id="ex:calculus">4.8 Numerical Integration and Differentiation</h1>
<p><a name="a0000000461" id="a0000000461"></a><a name="a0000000462" id="a0000000462"></a> Two special functions, <tt class="tt">int_dx()</tt><a name="a0000000463" id="a0000000463"></a> and <tt class="tt">diff_dx()</tt><a name="a0000000464" id="a0000000464"></a>, may be used to integrate or differentiate algebraic expressions numerically. In each case, the letter <tt class="tt">x</tt> is the dummy variable which is to be used in the integration or differentiation and may be replaced by any valid variable name of up to 16 characters in length. </p><p>The function <tt class="tt">int_dx()</tt> takes three parameters – firstly the expression to be integrated, which may optionally be placed in quotes, followed by the minimum and maximum integration limits. These may have any physical dimensions, so long as they match, but must both be real numbers. For example, the following would plot the integral of the function <img src="images/img-0015.png" alt="$\sin (x)$" style="vertical-align:-4px;
width:45px;
height:18px" class="math gen" />: </p><pre>
plot int_dt('sin(t)',0,x)
</pre><p>The function <tt class="tt">diff_dx()</tt> takes two obligatory parameters plus one further optional parameter. The first is the expression to be differentiated, which, as above, may optionally placed in quotes for clarity. This should be followed by the numerical value <img src="images/img-0019.png" alt="$x$" style="vertical-align:0px;
width:10px;
height:8px" class="math gen" /> of the dummy variable at the point where the expression is to be differentiated. This value may have any physical dimensions, and may be a complex number if complex arithmetic is enabled. The final, optional, parameter to the <tt class="tt">diff_dx()</tt> function is an approximate step size, which indicates the range of argument values over which PyXPlot should take samples to determine the gradient. If no value is supplied, a value of <img src="images/img-0129.png" alt="$10^{-6}x$" style="vertical-align:0px;
width:46px;
height:16px" class="math gen" /> is used, replaced by <img src="images/img-0130.png" alt="$10^{-6}$" style="vertical-align:0px;
width:35px;
height:16px" class="math gen" /> if <img src="images/img-0131.png" alt="$x=0$" style="vertical-align:0px;
width:43px;
height:12px" class="math gen" />. The following example would evaluate the differential of the function <img src="images/img-0010.png" alt="$\cos (x)$" style="vertical-align:-4px;
width:47px;
height:18px" class="math gen" /> with respect to <img src="images/img-0019.png" alt="$x$" style="vertical-align:0px;
width:10px;
height:8px" class="math gen" /> at <img src="images/img-0132.png" alt="$x=1.0$" style="vertical-align:0px;
width:57px;
height:12px" class="math gen" />: </p><p><table cellspacing="0" class="tabular">
<tr>
<td style="text-align:left"><p><img src="images/img-0030.png" alt="\includegraphics{tick}" style="width:19px; height:17px" />
</p></td>
<td style="text-align:left"><p><div style="width:0.0pt" class="minipage"><tt class="tt"> print diff_dx(’cos(x)’, 1.0) </tt></div></p></td>
</tr>
</table> </p><p>When complex arithmetic is enabled, PyXPlot checks that the function being differentiated satisfies the Cauchy-Riemann equations, and returns an error if it does not, to indicate that it is not differentiable. The following is an example of a function which is not differentiable, and which throws an error because the Cauchy-Riemann equations are not satisfied: </p><p><table cellspacing="0" class="tabular">
<tr>
<td style="text-align:left"><p><img src="images/img-0029.png" alt="\includegraphics{cross}" style="width:20px; height:24px" />
</p></td>
<td style="text-align:left"><p><div style="width:0.0pt" class="minipage"><tt class="tt"> set num comp<br />print diff_dx(Re(sin(x)),1) </tt></div></p></td>
</tr>
</table> </p><p>Advanced users may be interested to know that <tt class="tt">int_dx()</tt><a name="a0000000465" id="a0000000465"></a> function is implemented using the <tt class="tt">gsl_integration_qags()</tt> function of the Gnu Scientific Library<a name="a0000000466" id="a0000000466"></a> (GSL), and the <tt class="tt">diff_dx()</tt><a name="a0000000467" id="a0000000467"></a> function is implemented using the <tt class="tt">gsl_deriv_central()</tt> function of the same library. Any caveats which apply to the use of these routines also apply to PyXPlot’s numerical calculus. </p><p> <span class="upshape"><span class="mdseries"><span class="rm">Integrating the function <img src="images/img-0133.png" alt="$\mathrm{sinc}(x)$" style="vertical-align:-4px;
width:53px;
height:18px" class="math gen" />.</span></span></span></p><div>
<table cellspacing="0" class="tabular">
<tr>
<td style="border-top-style:solid; border-left:1px solid black; border-right:1px solid black; border-top-color:black; border-top-width:1px; text-align:left"><p> The function <img src="images/img-0133.png" alt="$\mathrm{sinc}(x)$" style="vertical-align:-4px;
width:53px;
height:18px" class="math gen" /> cannot be integrated analytically, but it can be shown that </p><table id="a0000000468" class="equation" width="100%" cellspacing="0" cellpadding="7">
<tr>
<td style="width:40%"> </td>
<td><img src="images/img-0134.png" alt="\[ \int _0^{\pm \infty } \mathrm{sinc}(x)\, \mathrm{d}x = \pm \pi /2 . \]" style="width:196px;
height:45px" class="math gen" /></td>
<td style="width:40%"> </td>
<td class="eqnnum" style="width:20%"> </td>
</tr>
</table><p> In the following script, we use PyXPlot’s facilities for numerical integration to produce a plot of </p><table id="a0000000469" class="equation" width="100%" cellspacing="0" cellpadding="7">
<tr>
<td style="width:40%"> </td>
<td><img src="images/img-0135.png" alt="\[ y=\int _0^{x} \mathrm{sinc}(x)\, \mathrm{d}x . \]" style="width:146px;
height:42px" class="math gen" /></td>
<td style="width:40%"> </td>
<td class="eqnnum" style="width:20%"> </td>
</tr>
</table><p> We reduce the number of samples taken along the abscissa axis to 80, as evaluation of the numerical integral may be time consuming on older computers. We use the <tt class="tt">set xformat</tt> command<a name="a0000000470" id="a0000000470"></a> (see Section <a href="sec-set_xformat.html">1.8.8</a>) to demark both the <tt class="tt">x</tt>- and <tt class="tt">y</tt>-axes in fractions of <img src="images/img-0136.png" alt="$\pi $" style="vertical-align:0px;
width:11px;
height:8px" class="math gen" />: </p></td>
</tr><tr>
<td style="text-align:left; border-right:1px solid black; border-left:1px solid black"><p><tt class="tt">set samples 80</tt><br /><tt class="tt">set key bottom right</tt><br /><tt class="tt">set xformat "%s$<img src="images/img-0006.png" alt="$\backslash $" style="vertical-align:-5px;
width:7px;
height:18px" class="math gen" />pi$"%(x/pi)</tt><br /><tt class="tt">set yformat "%s$<img src="images/img-0006.png" alt="$\backslash $" style="vertical-align:-5px;
width:7px;
height:18px" class="math gen" />pi$"%(y/pi)</tt><br /><tt class="tt">set xrange [-5*pi:5*pi]</tt><br /><tt class="tt">plot int_dz(sinc(z),0,x)</tt> </p></td>
</tr><tr>
<td style="border-bottom-style:solid; border-bottom-width:1px; border-left:1px solid black; border-right:1px solid black; text-align:left; border-bottom-color:black"><p><center>
<img src="images/img-0138.png" alt="\includegraphics[width=\textwidth ]{examples/eps/ex_integration}" style="width:" /></center> </p></td>
</tr>
</table>
</div></div>
<div class="navigation">
<table cellspacing="2" cellpadding="0" width="100%">
<tr>
<td><a href="sec-pastable.html" title="Creating Pastable Text"><img alt="Previous: Creating Pastable Text" border="0" src="icons/previous.gif" width="32" height="32" /></a></td>
<td><a href="sect0019.html" title="Performing Calculations"><img alt="Up: Performing Calculations" border="0" src="icons/up.gif" width="32" height="32" /></a></td>
<td><a href="sect0024.html" title="Solving Systems of Equations"><img alt="Next: Solving Systems of Equations" border="0" src="icons/next.gif" width="32" height="32" /></a></td>
<td class="navtitle" align="center">PyXPlot Users' Guide</td>
<td><a href="index.html" title="Table of Contents"><img border="0" alt="" src="icons/contents.gif" width="32" height="32" /></a></td>
<td><a href="sect0255.html" title="Index"><img border="0" alt="" src="icons/index.gif" width="32" height="32" /></a></td>
<td><img border="0" alt="" src="icons/blank.gif" width="32" height="32" /></td>
</tr>
</table>
</div>
<script language="javascript" src="icons/imgadjust.js" type="text/javascript"></script>
</body>
</html>
|