Popular recipes tagged "numerical"http://code.activestate.com/recipes/tags/numerical/2015-08-04T20:08:29-07:00ActiveState Code RecipesConverting numeric strings to integers (Python) 2015-08-04T20:08:29-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579093-converting-numeric-strings-to-integers/ <p style="color: grey"> Python recipe 579093 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/formats/">formats</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/numerical/">numerical</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/representation/">representation</a>). </p> <p>This recipe shows how to convert numeric strings into integers, i.e. it emulates the Python int() function - partially. It does not handle negative numbers, floating point numbers, or numbers in other bases than decimal. It is only meant as a simple demo of the steps by which a string containing an integer value, is converted into an actual integer, in Python (and similarly, in other languages).</p> Numerical Inversion of the Laplace Transform with mpmath (Python) 2013-12-27T05:10:12-08:00Pawel Olejnikhttp://code.activestate.com/recipes/users/4188852/http://code.activestate.com/recipes/578799-numerical-inversion-of-the-laplace-transform-with-/ <p style="color: grey"> Python recipe 578799 by <a href="/recipes/users/4188852/">Pawel Olejnik</a> (<a href="/recipes/tags/analysis/">analysis</a>, <a href="/recipes/tags/mpmath/">mpmath</a>, <a href="/recipes/tags/numerical/">numerical</a>). </p> <p>This Recipe is a variant of <a href="http://code.activestate.com/recipes/576934/">recipe 576934</a>: Numerical Inversion of the Laplace Transform using the Talbot method by Fernando Damian Nieuwveldt adapted to high precision mpmath</p> Numerical type with units (dimensions.py) (Python) 2010-07-24T17:24:13-07:00David Klaffenbachhttp://code.activestate.com/recipes/users/2007923/http://code.activestate.com/recipes/577333-numerical-type-with-units-dimensionspy/ <p style="color: grey"> Python recipe 577333 by <a href="/recipes/users/2007923/">David Klaffenbach</a> (<a href="/recipes/tags/dimensions/">dimensions</a>, <a href="/recipes/tags/numerical/">numerical</a>, <a href="/recipes/tags/units/">units</a>). </p> <p>I implemented dimensions.py perhaps eight years ago as an exercise and have used it occasionally ever since.</p> <p>It allows doing math with dimensioned values in order to automate unit conversions (you can add m/s to mile/hour) and dimensional checking (you can't add m/s to mile/lightyear). It specifically does not convert 212F to 100C but rather will convert 9F to 5C (valid when converting temperature differences).</p> <p>It is similar to unums (<a href="http://home.scarlet.be/be052320/Unum.html" rel="nofollow">http://home.scarlet.be/be052320/Unum.html</a>) but with a significant difference:</p> <p>I used a different syntax Q(25,'m/s') as opposed to 100*m/s (I recall not wanting to have all the base SI units directly in the namespace). I'm not entirely sure which approach is really better.</p> <p>I also had a specific need to have fractional exponents on units, allowing the following:</p> <pre class="prettyprint"><code>&gt;&gt;&gt; km=Q(10,'N*m/W^(1/2)') &gt;&gt;&gt; km Q(10.0, 'kg**0.5*m/s**0.5') </code></pre> <p>Looking back I see a few design decisions I might do differently today, but I'll share it anyway.</p> <p>Some examples are in the source below the line with if __name__ == "__main__":</p> <p>Note that I've put two files into the code block below, dimensions.py and dimensions.data, so please cut them apart if you want to try it.</p> Numerical Inversion of the Laplace Transform using the Talbot method. (Python) 2009-10-27T04:53:30-07:00Fernando Nieuwveldthttp://code.activestate.com/recipes/users/4172088/http://code.activestate.com/recipes/576934-numerical-inversion-of-the-laplace-transform-using/ <p style="color: grey"> Python recipe 576934 by <a href="/recipes/users/4172088/">Fernando Nieuwveldt</a> (<a href="/recipes/tags/analysis/">analysis</a>, <a href="/recipes/tags/laplace/">laplace</a>, <a href="/recipes/tags/numerical/">numerical</a>). Revision 5. </p> <p>This is a fast and highly accurate numerical method for the inversion of the Laplace transform</p> Numerical Inversion of the Laplace Transform with mpmath (Python) 2009-10-27T01:48:22-07:00Dieter Kadelkahttp://code.activestate.com/recipes/users/4172107/http://code.activestate.com/recipes/576938-numerical-inversion-of-the-laplace-transform-with-/ <p style="color: grey"> Python recipe 576938 by <a href="/recipes/users/4172107/">Dieter Kadelka</a> (<a href="/recipes/tags/analysis/">analysis</a>, <a href="/recipes/tags/mpmath/">mpmath</a>, <a href="/recipes/tags/numerical/">numerical</a>). </p> <p>This Recipe is a variant of <a href="http://code.activestate.com/recipes/576934/">recipe 576934</a>: Numerical Inversion of the Laplace Transform using the Talbot method by Fernando Damian Nieuwveldt adapted to high precision mpmath</p> Newton Raphson Root Finding (Python) 2009-05-19T05:18:00-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/576762-newton-raphson-root-finding/ <p style="color: grey"> Python recipe 576762 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/numerical/">numerical</a>, <a href="/recipes/tags/scipy/">scipy</a>). </p> <p>Newton Raphson Root Finding</p> Poor man's mgrid (Python) 2009-01-21T15:37:13-08:00David Lamberthttp://code.activestate.com/recipes/users/4167420/http://code.activestate.com/recipes/576625-poor-mans-mgrid/ <p style="color: grey"> Python recipe 576625 by <a href="/recipes/users/4167420/">David Lambert</a> (<a href="/recipes/tags/index/">index</a>, <a href="/recipes/tags/index_tricks/">index_tricks</a>, <a href="/recipes/tags/method/">method</a>, <a href="/recipes/tags/mgrid/">mgrid</a>, <a href="/recipes/tags/numerical/">numerical</a>, <a href="/recipes/tags/numerical_methods/">numerical_methods</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/scipy/">scipy</a>, <a href="/recipes/tags/trick/">trick</a>). </p> <p>Python 3 code. scipy.mgrid is a useful! This short implementation comes without installing numpy.</p>