Latest recipes tagged "mathematics"http://code.activestate.com/recipes/tags/mathematics/new/2016-07-31T22:50:28-07:00ActiveState Code RecipesImage Projection Onto Sphere (Python) 2016-07-31T22:50:28-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/580695-image-projection-onto-sphere/ <p style="color: grey"> Python recipe 580695 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/images/">images</a>, <a href="/recipes/tags/image_processing/">image_processing</a>, <a href="/recipes/tags/imaging/">imaging</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/pil/">pil</a>). </p> <p>Image projection onto sphere using Equirectangular map projection.</p> <p>Download the test image from the Wikipedia page!</p> Hamming Error Correction Code (Python) 2016-07-23T07:58:14-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/580691-hamming-error-correction-code/ <p style="color: grey"> Python recipe 580691 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/encoding/">encoding</a>, <a href="/recipes/tags/engineering/">engineering</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>Hamming(7,4) Error Correction Code (ECC).</p> Random Planet Generator Using Plasma Fractal (Python) 2016-01-25T23:05:25-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/580495-random-planet-generator-using-plasma-fractal/ <p style="color: grey"> Python recipe 580495 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/images/">images</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>). </p> <p>Random Planet Generator using 3D Plasma Fractal and Voxel-based Ray Tracing for rendering.</p> <p>Instead of generating 2D Plasma Fractal and projecting onto sphere, it generates 3D Plasma Fractal (cube) and cuts sphere from it.</p> Mandelbrot 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> Infix Expression Evaluation (Python) 2015-11-08T05:08:26-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/579123-infix-expression-evaluation/ <p style="color: grey"> Python recipe 579123 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/stack/">stack</a>). </p> <p>Infix expression evaluation using two stacks.</p> Simple Infix Expression Evaluation (Python) 2015-11-07T18:44:05-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/579122-simple-infix-expression-evaluation/ <p style="color: grey"> Python recipe 579122 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/stack/">stack</a>). </p> <p>Simple infix expression evaluation using a stack.</p> Reaction Diffusion Simulation (Python) 2015-10-16T19:52:02-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/579114-reaction-diffusion-simulation/ <p style="color: grey"> Python recipe 579114 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/chaos/">chaos</a>, <a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/images/">images</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/physics/">physics</a>, <a href="/recipes/tags/simulation/">simulation</a>). Revision 2. </p> <p>Reaction-Diffusion Simulation using Gray-Scott Model.</p> Quasicrystal Pattern Generator (Python) 2015-08-08T20:50:23-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/579094-quasicrystal-pattern-generator/ <p style="color: grey"> Python recipe 579094 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/images/">images</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>). </p> <p>Quasicrystal Pattern Generator</p> Mandelbrot Fractal image output to ppm file (Python) 2015-01-17T19:21:47-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/579006-mandelbrot-fractal-image-output-to-ppm-file/ <p style="color: grey"> Python recipe 579006 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/images/">images</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>). </p> <p>It creates image output without using any external library.</p> <p>PPM image files can be viewed and converted to other image file formats using many applications, GIMP or IrfanView for example.</p> 2D Discrete Fourier Transform (Python) 2015-01-03T03:39:34-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578997-2d-discrete-fourier-transform/ <p style="color: grey"> Python recipe 578997 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/images/">images</a>, <a href="/recipes/tags/image_processing/">image_processing</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/signal_processing/">signal_processing</a>). </p> <p>2D Discrete Fourier Transform (DFT) and its inverse.</p> <p>Calculates 2D DFT of an image and recreates the image using inverse 2D DFT.</p> <p>Computation is slow so only suitable for thumbnail size images.</p> Discrete Fourier Transform (Python) 2014-12-27T21:43:53-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578994-discrete-fourier-transform/ <p style="color: grey"> Python recipe 578994 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/signal/">signal</a>, <a href="/recipes/tags/signal_processing/">signal_processing</a>). </p> <p>Discrete Fourier Transform and Inverse Discrete Fourier Transform</p> <p>To test, it creates an input signal using a Sine wave that has known frequency, amplitude, phase. Later it calculates DFT of the input signal and finds its frequency, amplitude, phase to compare.</p> A Fun Perfect Square Checker Using Integer Arithmetic Only... ;o) (Bash) 2014-09-16T22:27:04-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578934-a-fun-perfect-square-checker-using-integer-arithme/ <p style="color: grey"> Bash recipe 578934 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/arithmetic/">arithmetic</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/check/">check</a>, <a href="/recipes/tags/checker/">checker</a>, <a href="/recipes/tags/cygwin/">cygwin</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/perfect/">perfect</a>, <a href="/recipes/tags/root/">root</a>, <a href="/recipes/tags/square/">square</a>). </p> <p>A recent Python upload here gave me the inspiration to do a bash version... This is a little tongue-in-cheek but an enjoyable bit of fun.</p> <p>It took around 11 seconds to prove 90000000000 had a perfect square of 300000...</p> <p>It is a stand alone program and has a degree of INPUT error correction...</p> <p>It was done on a MacBook Pro, OSX 10.7.5, default bash terminal and should work on Linux flavours but it is untested...</p> <p>Enjoy finding simple solutions to often very difficult problems...</p> <p>Bazza...</p> Perfect Square Checker (Python) 2014-09-10T02:21:27-07:00Ethan Hannhttp://code.activestate.com/recipes/users/4190746/http://code.activestate.com/recipes/578931-perfect-square-checker/ <p style="color: grey"> Python recipe 578931 by <a href="/recipes/users/4190746/">Ethan Hann</a> (<a href="/recipes/tags/check/">check</a>, <a href="/recipes/tags/checker/">checker</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/root/">root</a>, <a href="/recipes/tags/square/">square</a>). </p> <p>This program will take input from the user and either check if a number is a perfect square or square a number, depending on user's choice.</p> 2D Fluid Simulation using FHP LGCA (Python) 2014-08-18T05:01:04-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578924-2d-fluid-simulation-using-fhp-lgca/ <p style="color: grey"> Python recipe 578924 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/physics/">physics</a>, <a href="/recipes/tags/simulation/">simulation</a>). </p> <p>2D Fluid Simulation using FHP LGCA (Lattice Gas Cellular Automata)</p> <p>Simulates fluid flow in a circular channel.</p> <p>It works really slow but I think it can be a lot faster if it modified for NumPy and possibly Py2Exe.</p> <p>But my main goal was to provide easy to understand code (not performance) anyway. </p> Automated Stock Market Trading Simulation (Python) 2014-05-16T02:40:28-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578881-automated-stock-market-trading-simulation/ <p style="color: grey"> Python recipe 578881 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/simulation/">simulation</a>, <a href="/recipes/tags/stock/">stock</a>, <a href="/recipes/tags/stock_market/">stock_market</a>). </p> <p>It simulates an automated trading strategy against a simulated stock.</p> <p>I think the results are interesting. It seems number of wins are always higher than number of losses but average amount of loss is also always higher than average amount of win! </p> Circle Inversion Fractals (Python) 2013-10-30T03:53:31-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578765-circle-inversion-fractals/ <p style="color: grey"> Python recipe 578765 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>). </p> <p>Circle Inversion Fractals (Apollonian Gasket)</p> Hofstadter Butterfly Fractal (Python) 2013-09-23T03:18:02-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578670-hofstadter-butterfly-fractal/ <p style="color: grey"> Python recipe 578670 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/physics/">physics</a>). Revision 2. </p> <p>Hofstadter Butterfly Fractal</p> Random Spiral Fractals (Python) 2013-09-29T05:35:20-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578658-random-spiral-fractals/ <p style="color: grey"> Python recipe 578658 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>). Revision 2. </p> <p>This based on another of my posted codes, titled "Spiral IFS Fractals".</p> Calculating e using Continued Fraction (Python) 2013-09-02T18:49:53-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578653-calculating-e-using-continued-fraction/ <p style="color: grey"> Python recipe 578653 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>). </p> <p>Calculating e using Continued Fraction</p> Voxel Based Ray Tracing (Python) 2013-08-29T06:11:41-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578652-voxel-based-ray-tracing/ <p style="color: grey"> Python recipe 578652 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>). </p> <p>The standard ray tracing algorithm seems unnatural to me because everytime a ray reflects/refracts all (primitive) objects in the scene must be tested for intersection; no matter where they located!</p> <p>In this method there is no such thing. It just moves each ray voxel by voxel until it hits an opaque/reflective(/refractive) voxel.</p> <p>I made many simplifications so the image is crude.</p>