Popular recipes tagged "mathematics" but not "math"http://code.activestate.com/recipes/tags/mathematics-math/2015-12-28T17:56:08-08:00ActiveState Code RecipesMandelbrot Set made simple (Python)
2015-12-28T17:56:08-08:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/579143-mandelbrot-set-made-simple/
<p style="color: grey">
Python
recipe 579143
by <a href="/recipes/users/4076953/">Jack Trainor</a>
(<a href="/recipes/tags/educational/">educational</a>, <a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/mandelbrot/">mandelbrot</a>, <a href="/recipes/tags/mathematics/">mathematics</a>).
Revision 2.
</p>
<p>This is a mini-framework for exploring the Mandelbrot Set.</p>
<p>It outputs to a Tkinter window or to a PNG file (Pillow package required). It includes a disk caching mechanism for saving and later retrieving Mandelbrot calculations to avoid recalculating the Set on each run.</p>
<p>See module documentation for further information. Compatible with Python 2 and 3.</p>
Fixed Point Iteration in Python (Python)
2013-01-16T16:39:08-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578418-fixed-point-iteration-in-python/
<p style="color: grey">
Python
recipe 578418
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/fixed_point/">fixed_point</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>The code utilizes fixed point iteration to solve equations in python. This code was wrriten for <a href="http://thelivingpearl.com/2013/01/15/the-easy-way-to-solve-equations-in-python/">How to solve equations using python</a>.</p>
Bisection Method in Python (Python)
2013-01-16T16:37:33-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578417-bisection-method-in-python/
<p style="color: grey">
Python
recipe 578417
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/bisect/">bisect</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>This is a quick way to do bisection method in python. I wrote his code as part of an article, <a href="http://thelivingpearl.com/2013/01/15/the-easy-way-to-solve-equations-in-python/">How to solve equations using python</a></p>
Generate the parity or sign of a permutation (Python)
2012-07-28T07:21:49-07:00Paddy McCarthyhttp://code.activestate.com/recipes/users/398009/http://code.activestate.com/recipes/578227-generate-the-parity-or-sign-of-a-permutation/
<p style="color: grey">
Python
recipe 578227
by <a href="/recipes/users/398009/">Paddy McCarthy</a>
(<a href="/recipes/tags/determinants/">determinants</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/matrix/">matrix</a>, <a href="/recipes/tags/permutations/">permutations</a>).
</p>
<p>The <a href="http://en.wikipedia.org/wiki/Parity_of_a_permutation">parity</a> of a given permutation is whether an odd or even number of swaps between any two elements are needed to transform the given permutation to the first permutation.</p>
<p>The sign of the permutation is +1 for an even parity and -1 for an odd parity.</p>
<p>This python function returns the sign of a permutation of all the integers 0..N.
When the program is run it shows the sign of permutations as generated by the standard function itertools.permutations.</p>
<p>The function uses a modified <a href="http://rosettacode.org/wiki/Sorting_algorithms/Selection_sort#Python">selection sort</a> to compute the parity.</p>
Secant Method of Solving Equtions in Python (Python)
2013-01-16T16:42:26-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578420-secant-method-of-solving-equtions-in-python/
<p style="color: grey">
Python
recipe 578420
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/pytho/">pytho</a>, <a href="/recipes/tags/secant/">secant</a>).
</p>
<p>Solving equations using the Newton's method without taking derivatives. This code war written for the article <a href="http://thelivingpearl.com/2013/01/15/the-easy-way-to-solve-equations-in-python/">How to solve equations using python</a>.</p>
Newton's Method to Solve Equations in Python (Python)
2013-01-16T16:40:55-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578419-newtons-method-to-solve-equations-in-python/
<p style="color: grey">
Python
recipe 578419
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/newtons_method/">newtons_method</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>This is how you would use Newton's method to solve equations. For more information about solving equations in python checkout <a href="http://thelivingpearl.com/2013/01/15/the-easy-way-to-solve-equations-in-python/">How to solve equations using python</a>.</p>
Alternatve generation of the parity or sign of a permutation (Python)
2012-08-07T08:45:23-07:00Paddy McCarthyhttp://code.activestate.com/recipes/users/398009/http://code.activestate.com/recipes/578236-alternatve-generation-of-the-parity-or-sign-of-a-p/
<p style="color: grey">
Python
recipe 578236
by <a href="/recipes/users/398009/">Paddy McCarthy</a>
(<a href="/recipes/tags/determinants/">determinants</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/matrix/">matrix</a>, <a href="/recipes/tags/permutations/">permutations</a>).
</p>
<p>Although <a href="http://code.activestate.com/recipes/578227/">Recipe 578227</a> was straight-forward to derive, I came across <a href="http://stackoverflow.com/questions/337664/counting-inversions-in-an-array/6424847#6424847">this Stack Overflow answer</a> that gives another method for generating the sign based on comparing the perm and the sorted perm.</p>
DictSet - A specialized Python container datatype for managing collections of sets. (Python)
2011-05-18T21:18:54-07:00Roger Lewhttp://code.activestate.com/recipes/users/4178017/http://code.activestate.com/recipes/577702-dictset-a-specialized-python-container-datatype-fo/
<p style="color: grey">
Python
recipe 577702
by <a href="/recipes/users/4178017/">Roger Lew</a>
(<a href="/recipes/tags/analysis/">analysis</a>, <a href="/recipes/tags/development/">development</a>, <a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/information/">information</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/sets/">sets</a>).
</p>
<p>The basic Python container types (dict, list, set, and tuple) are extremely versatile and powerful. The collections module first implemented in Python 2.4 has shown that sub-classing these containers can yield elegant solutions to the right problem. In a similar vein this project is a dict subclass for elegantly handling collections of sets. In many aspects a DictSet is similiar to a defaultdict of sets except it generalizes many of the set operations to the dict.</p>
<p>Put simply, DictSet is a dict of sets that behaves like a set.</p>
<p>DictSet requires 0 non-standard dependencies and should work with Python 2.5 and up.</p>
interleave bits (aka morton-ize aka z-order curve) (Python)
2011-02-02T12:50:58-08:00Romain Dartigueshttp://code.activestate.com/recipes/users/4167472/http://code.activestate.com/recipes/577558-interleave-bits-aka-morton-ize-aka-z-order-curve/
<p style="color: grey">
Python
recipe 577558
by <a href="/recipes/users/4167472/">Romain Dartigues</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/bits/">bits</a>, <a href="/recipes/tags/manipulation/">manipulation</a>, <a href="/recipes/tags/mathematical/">mathematical</a>, <a href="/recipes/tags/mathematics/">mathematics</a>).
</p>
<p>This recipe let you encode in a single number two or three numbers.</p>
<p>Note: this is only an adaptation of the recipes from <strong>Sean Eron Anderson</strong> and <strong>Fabian “ryg” Giesen</strong>; all credits goes to the respective authors.</p>
<ul>
<li><a href="http://graphics.stanford.edu/%7Eseander/bithacks.html#InterleaveBMN" rel="nofollow">http://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN</a></li>
<li><a href="http://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/" rel="nofollow">http://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/</a></li>
</ul>
Maclaurin's_series_exponential(x) (Python)
2010-07-07T12:52:28-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577293-maclaurins_series_exponentialx/
<p style="color: grey">
Python
recipe 577293
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/mathematics/">mathematics</a>).
</p>
<p>C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p>
<p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices .</p>
<p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p>
<p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor series. </p>
<p>The natural exponential function e^x has a constant base e and a variable x and Maclaurin's series to approximate the natural exponential converge on the interval ]-inf , + inf [.</p>
Maclaurin's_series_sin (Python)
2010-07-07T12:05:33-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577287-maclaurins_series_sin/
<p style="color: grey">
Python
recipe 577287
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/mathematics/">mathematics</a>).
</p>
<p>C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p>
<p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices.</p>
<p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p>
<p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor series. </p>
<p>It is assumed that the angle is expressed in radian while using the Maclaurin's series to approximate the trigonometric functions sine and cosine, thus, converting the angle into degrees in my program could be useful for students who prefer using degrees.</p>
Maclaurin's_series_tanh-1(x) (Python)
2010-09-28T11:50:45-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577399-maclaurins_series_tanh-1x/
<p style="color: grey">
Python
recipe 577399
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/mathematics/">mathematics</a>).
</p>
<p>C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p>
<p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices .</p>
<p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p>
<p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor's series. </p>
<p>Natural logarithms are used to compute inverse hyperbolic functions.</p>
Maclaurin's_series_sinh-1(x) (Python)
2010-09-28T11:52:21-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577401-maclaurins_series_sinh-1x/
<p style="color: grey">
Python
recipe 577401
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/mathematics/">mathematics</a>).
</p>
<p>C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p>
<p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices .</p>
<p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p>
<p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor's series. </p>
<p>Natural logarithms are used to compute inverse hyperbolic functions.</p>
Maclaurin's_series_cosh-1(x) (Python)
2010-09-28T11:53:08-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577400-maclaurins_series_cosh-1x/
<p style="color: grey">
Python
recipe 577400
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/mathematics/">mathematics</a>).
</p>
<p>C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p>
<p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices .</p>
<p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p>
<p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor's series. </p>
<p>Natural logarithms are used to compute inverse hyperbolic functions.</p>
Maclaurin's_series_cos (Python)
2010-07-07T11:56:52-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577285-maclaurins_series_cos/
<p style="color: grey">
Python
recipe 577285
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/mathematics/">mathematics</a>).
Revision 2.
</p>
<p>Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p>
<p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices .</p>
<p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p>
<p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor series. </p>
<p>It is assumed that the angle is expressed in radian while using the Maclaurin's series to approximate the trigonometric functions sine and cosine, thus, converting the angle into degrees in my program could be useful for students who prefer using degrees.</p>
Maclaurin's_series_cos(2x) (Python)
2010-08-03T12:23:33-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577344-maclaurins_series_cos2x/
<p style="color: grey">
Python
recipe 577344
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/mathematics/">mathematics</a>).
Revision 2.
</p>
<p>C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p>
<p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices .</p>
<p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p>
<p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor series. </p>
<p>There are several ways of finding Maclaurin’s series, and I used the multiplication and the division to develop my own maclaurin’s series for cos(2x) and cos²(x).</p>
<p>Cos(2x) = 2cos²(x) - 1 and cos²(x) = (cos(2x)+1)/2</p>
<p>However, integration and differentiation could also be used to find Maclaurin’s series. </p>
Maclaurin's_series_cos² (x) (Python)
2010-08-03T12:21:22-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577345-maclaurins_series_cos2-x/
<p style="color: grey">
Python
recipe 577345
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/mathematics/">mathematics</a>).
Revision 4.
</p>
<p>C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p>
<p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices .</p>
<p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p>
<p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor series. </p>
<p>There are several ways of finding Maclaurin’s series, and I used the multiplication and the division to develop my own maclaurin’s series for cos(2x) and cos²(x).</p>
<p>Cos(2x) = 2cos²(x) - 1 and cos²(x) = (cos(2x)+1)/2</p>
<p>However, integration and differentiation could also be used to find Maclaurin’s series. </p>
Maclaurin's_series_ln(x) (Python)
2010-07-15T11:16:30-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577300-maclaurins_series_lnx/
<p style="color: grey">
Python
recipe 577300
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/mathematics/">mathematics</a>).
Revision 8.
</p>
<p>C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p>
<p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices .</p>
<p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p>
<p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor series. </p>
<p>The maclaurin's series approximation for ln(1+x) is used to approximate ln(x) by detucting the maclaurin's series for ln(1-x).
ln(1+x) - ln(1-x) = ln(1+x/1-x)and by letting y = (1+x/1-x), y could take any positive value.</p>
<p>y = 1+x/1-x, therefore x = y-1/y+1 </p>
<p>-1 < x < 1 </p>
Maclaurin's_series_function(1/1-x) (Python)
2010-07-07T12:36:23-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577291-maclaurins_series_function11-x/
<p style="color: grey">
Python
recipe 577291
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/mathematics/">mathematics</a>).
</p>
<p>C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p>
<p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices .</p>
<p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p>
<p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor series.</p>
<p>Maclaurin's series to approximate f(x) = 1/1-x</p>
Maclaurin's_series_ln(x)_decimal_module_version (Python)
2011-01-20T12:09:24-08:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577307-maclaurins_series_lnx_decimal_module_version/
<p style="color: grey">
Python
recipe 577307
by <a href="/recipes/users/4155345/">Fouad Teniou</a>
(<a href="/recipes/tags/mathematics/">mathematics</a>).
Revision 5.
</p>
<p>C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p>
<p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices .</p>
<p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p>
<p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor series. </p>
<p>The maclaurin's series approximation for ln(1+x) is used to approximate ln(x) by detucting the maclaurin's series for ln(1-x). ln(1+x) - ln(1-x) = ln(1+x/1-x)and by letting y = (1+x/1-x), y could take any positive value.</p>
<p>y = 1+x/1-x, therefore x = y-1/y+1 </p>
<p>-1 < x < 1</p>