| 
0
 | 
     1 <html>
 | 
| 
 | 
     2 <head>
 | 
| 
 | 
     3 <title>MayaChemTools:Documentation:MathUtil.pm</title>
 | 
| 
 | 
     4 <meta http-equiv="content-type" content="text/html;charset=utf-8">
 | 
| 
 | 
     5 <link rel="stylesheet" type="text/css" href="../../css/MayaChemTools.css">
 | 
| 
 | 
     6 </head>
 | 
| 
 | 
     7 <body leftmargin="20" rightmargin="20" topmargin="10" bottommargin="10">
 | 
| 
 | 
     8 <br/>
 | 
| 
 | 
     9 <center>
 | 
| 
 | 
    10 <a href="http://www.mayachemtools.org" title="MayaChemTools Home"><img src="../../images/MayaChemToolsLogo.gif" border="0" alt="MayaChemTools"></a>
 | 
| 
 | 
    11 </center>
 | 
| 
 | 
    12 <br/>
 | 
| 
 | 
    13 <div class="DocNav">
 | 
| 
 | 
    14 <table width="100%" border=0 cellpadding=0 cellspacing=2>
 | 
| 
 | 
    15 <tr align="left" valign="top"><td width="33%" align="left"><a href="./HTMLUtil.html" title="HTMLUtil.html">Previous</a>  <a href="./index.html" title="Table of Contents">TOC</a>  <a href="./Matrix.html" title="Matrix.html">Next</a></td><td width="34%" align="middle"><strong>MathUtil.pm</strong></td><td width="33%" align="right"><a href="././code/MathUtil.html" title="View source code">Code</a> | <a href="./../pdf/MathUtil.pdf" title="PDF US Letter Size">PDF</a> | <a href="./../pdfgreen/MathUtil.pdf" title="PDF US Letter Size with narrow margins: www.changethemargins.com">PDFGreen</a> | <a href="./../pdfa4/MathUtil.pdf" title="PDF A4 Size">PDFA4</a> | <a href="./../pdfa4green/MathUtil.pdf" title="PDF A4 Size with narrow margins: www.changethemargins.com">PDFA4Green</a></td></tr>
 | 
| 
 | 
    16 </table>
 | 
| 
 | 
    17 </div>
 | 
| 
 | 
    18 <p>
 | 
| 
 | 
    19 </p>
 | 
| 
 | 
    20 <h2>NAME</h2>
 | 
| 
 | 
    21 <p>MathUtil</p>
 | 
| 
 | 
    22 <p>
 | 
| 
 | 
    23 </p>
 | 
| 
 | 
    24 <h2>SYNOPSIS</h2>
 | 
| 
 | 
    25 <p>use MathUtil;</p>
 | 
| 
 | 
    26 <p>use MathUtil qw(:all);</p>
 | 
| 
 | 
    27 <p>
 | 
| 
 | 
    28 </p>
 | 
| 
 | 
    29 <h2>DESCRIPTION</h2>
 | 
| 
 | 
    30 <p><strong>MathUtil</strong> module provides a variety of common math functions not available in core
 | 
| 
 | 
    31 Perl package or some other useful math utilities. In order to be consistent with other
 | 
| 
 | 
    32 Perl functions, name of all the functions in this package are in lowercase which differs
 | 
| 
 | 
    33 from MayaChemTools naming convention for function names.</p>
 | 
| 
 | 
    34 <p><strong>MathUtil</strong> module provides the following functions:</p>
 | 
| 
 | 
    35 <p> <a href="#generateprimenumbersuptocount">GeneratePrimeNumbersUpToCount</a>, <a href="#generateprimenumbersuptolimit">GeneratePrimeNumbersUpToLimit</a>, <a href="#acos">acos</a>, <a href="#asin">asin</a>, <a href="#ceil">ceil</a>
 | 
| 
 | 
    36 , <a href="#floor">floor</a>, <a href="#log10">log10</a>, <a href="#max">max</a>, <a href="#min">min</a>, <a href="#random">random</a>, <a href="#round">round</a>, <a href="#srandom">srandom</a>, <a href="#tan">tan</a>
 | 
| 
 | 
    37 </p><p>
 | 
| 
 | 
    38 </p>
 | 
| 
 | 
    39 <h2>FUNCTIONS</h2>
 | 
| 
 | 
    40 <dl>
 | 
| 
 | 
    41 <dt><strong><a name="generateprimenumbersuptocount" class="item"><strong>GeneratePrimeNumbersUpToCount</strong></a></strong></dt>
 | 
| 
 | 
    42 <dd>
 | 
| 
 | 
    43 <div class="OptionsBox">
 | 
| 
 | 
    44     $PrimesRef = GeneratePrimeNumbersUpToCount();
 | 
| 
 | 
    45 <br/>    $PrimesRef = GeneratePrimeNumbersUpToCount($Count);</div>
 | 
| 
 | 
    46 <p>Generate prime numbers up to specified <em>Count</em> of prime numbers and return a
 | 
| 
 | 
    47 reference to an array containing the prime numbers.</p>
 | 
| 
 | 
    48 <p>By default, the first 1000 prime numbers are generated. The 1000th prime
 | 
| 
 | 
    49 number is 7919.</p>
 | 
| 
 | 
    50 <p>The algorithm to generate prime numbers is a modification of  Sieve of Erastothenes
 | 
| 
 | 
    51 prime number generator.</p>
 | 
| 
 | 
    52 </dd>
 | 
| 
 | 
    53 <dt><strong><a name="generateprimenumbersuptolimit" class="item"><strong>GeneratePrimeNumbersUpToLimit</strong></a></strong></dt>
 | 
| 
 | 
    54 <dd>
 | 
| 
 | 
    55 <div class="OptionsBox">
 | 
| 
 | 
    56     $PrimesRef = GeneratePrimeNumbersUpToLimit();
 | 
| 
 | 
    57 <br/>    $PrimesRef = GeneratePrimeNumbersUpToLimit($Limit);</div>
 | 
| 
 | 
    58 <p>Generate prime numbers up to a specified <em>Limit</em> and return a reference to an
 | 
| 
 | 
    59 array containing the prime numbers.</p>
 | 
| 
 | 
    60 <p>By default, the first 1000 prime numbers are generated. The 1000th prime
 | 
| 
 | 
    61 number is 7919 and that's why default limit is set to 7920.</p>
 | 
| 
 | 
    62 <p>The algorithm to generate prime numbers is a modification of  Sieve of Erastothenes
 | 
| 
 | 
    63 prime number generator.</p>
 | 
| 
 | 
    64 </dd>
 | 
| 
 | 
    65 <dt><strong><a name="acos" class="item"><strong>acos</strong></a></strong></dt>
 | 
| 
 | 
    66 <dd>
 | 
| 
 | 
    67 <div class="OptionsBox">
 | 
| 
 | 
    68     $Value = acos($AngleInRadians);</div>
 | 
| 
 | 
    69 <p>Returns the nverse cosine of an angle expressed in <em>Radians</em> using Math::Trig::acos
 | 
| 
 | 
    70 function.</p>
 | 
| 
 | 
    71 </dd>
 | 
| 
 | 
    72 <dt><strong><a name="asin" class="item"><strong>asin</strong></a></strong></dt>
 | 
| 
 | 
    73 <dd>
 | 
| 
 | 
    74 <div class="OptionsBox">
 | 
| 
 | 
    75     $Value = asin($AngleInRadians);</div>
 | 
| 
 | 
    76 <p>Returns the inverse sine of an angle expressed in <em>Radians</em> using Math::Trig::asin
 | 
| 
 | 
    77 function.</p>
 | 
| 
 | 
    78 </dd>
 | 
| 
 | 
    79 <dt><strong><a name="ceil" class="item"><strong>ceil</strong></a></strong></dt>
 | 
| 
 | 
    80 <dd>
 | 
| 
 | 
    81 <div class="OptionsBox">
 | 
| 
 | 
    82     $IntegerValue = ceil($Value);</div>
 | 
| 
 | 
    83 <p>Returns the next largest integer for <em>Value</em> using POSIX::ceil function.</p>
 | 
| 
 | 
    84 </dd>
 | 
| 
 | 
    85 <dt><strong><a name="floor" class="item"><strong>floor</strong></a></strong></dt>
 | 
| 
 | 
    86 <dd>
 | 
| 
 | 
    87 <div class="OptionsBox">
 | 
| 
 | 
    88     $IntegerValue = floor($Value);</div>
 | 
| 
 | 
    89 <p>Returns the previous smallest integer for <em>Value</em> using POSIX::floor function.</p>
 | 
| 
 | 
    90 </dd>
 | 
| 
 | 
    91 <dt><strong><a name="log10" class="item"><strong>log10</strong></a></strong></dt>
 | 
| 
 | 
    92 <dd>
 | 
| 
 | 
    93 <div class="OptionsBox">
 | 
| 
 | 
    94     $Log10Value = log10($Value);</div>
 | 
| 
 | 
    95 <p>Returns the log of <em>Value</em> using base 10.</p>
 | 
| 
 | 
    96 </dd>
 | 
| 
 | 
    97 <dt><strong><a name="max" class="item"><strong>max</strong></a></strong></dt>
 | 
| 
 | 
    98 <dd>
 | 
| 
 | 
    99 <div class="OptionsBox">
 | 
| 
 | 
   100     $Number = max($Number1, $Number2);</div>
 | 
| 
 | 
   101 <p>Returns a <strong>Number</strong> corresponding to the maximum of <em>Number1</em> and <em>Number2</em>.</p>
 | 
| 
 | 
   102 </dd>
 | 
| 
 | 
   103 <dt><strong><a name="min" class="item"><strong>min</strong></a></strong></dt>
 | 
| 
 | 
   104 <dd>
 | 
| 
 | 
   105 <div class="OptionsBox">
 | 
| 
 | 
   106     $Number = min($Number1, $Number2);</div>
 | 
| 
 | 
   107 <p>Returns a <strong>Number</strong> corresponding to the minimum of <em>Number1</em> and <em>Number2</em>.</p>
 | 
| 
 | 
   108 </dd>
 | 
| 
 | 
   109 <dt><strong><a name="round" class="item"><strong>round</strong></a></strong></dt>
 | 
| 
 | 
   110 <dd>
 | 
| 
 | 
   111 <div class="OptionsBox">
 | 
| 
 | 
   112     $RoundedValue = round($Number);
 | 
| 
 | 
   113 <br/>    $RoundedValue = round($Number, $DecimalPlaces);</div>
 | 
| 
 | 
   114 <p>Returns a value corresponding to a nearst ingeter for <em>Number</em> or formatted to <em>DecimalPlaces</em>.</p>
 | 
| 
 | 
   115 </dd>
 | 
| 
 | 
   116 <dt><strong><a name="random" class="item"><strong>random</strong></a></strong></dt>
 | 
| 
 | 
   117 <dd>
 | 
| 
 | 
   118 <div class="OptionsBox">
 | 
| 
 | 
   119     $RandomNumber = random();
 | 
| 
 | 
   120 <br/>    $RandomNumber = random($Size);</div>
 | 
| 
 | 
   121 <p>Returns a random number between 0 and less than 1 or specified size.</p>
 | 
| 
 | 
   122 <p>The random number generator implemented in MayaChemTools is a variant of linear
 | 
| 
 | 
   123 congruential generator (LCG) as described by Miller et al. [ Ref 120 ]. It is
 | 
| 
 | 
   124 also referred to as Lehmer random number generator or Park-Miller random number
 | 
| 
 | 
   125 generator.</p>
 | 
| 
 | 
   126 <p>Unlike Perl's core random number generator function rand, the random number
 | 
| 
 | 
   127 generator implemented in MayaChemTools generates consistent random values
 | 
| 
 | 
   128 across different platforms - Windows, CygWin, Linux, Unix - for a specific random
 | 
| 
 | 
   129 seed.</p>
 | 
| 
 | 
   130 </dd>
 | 
| 
 | 
   131 <dt><strong><a name="srandom" class="item"><strong>srandom</strong></a></strong></dt>
 | 
| 
 | 
   132 <dd>
 | 
| 
 | 
   133 <div class="OptionsBox">
 | 
| 
 | 
   134     $Seed = srandom($Seed);</div>
 | 
| 
 | 
   135 <p>Sets random number seed to be used by <random> function and returns seed value.</p>
 | 
| 
 | 
   136 <p>The random number seed is recommeded to be an integer between 1 and 2**31 - 2
 | 
| 
 | 
   137 [Ref 120] which translates to be 1 and 2147483646.</p>
 | 
| 
 | 
   138 <p>The default seed is set to 123456789.</p>
 | 
| 
 | 
   139 </dd>
 | 
| 
 | 
   140 <dt><strong><a name="tan" class="item"><strong>tan</strong></a></strong></dt>
 | 
| 
 | 
   141 <dd>
 | 
| 
 | 
   142 <div class="OptionsBox">
 | 
| 
 | 
   143     $Value = tan($AngleInRadians);</div>
 | 
| 
 | 
   144 <p>Returns the tangent of an angle expressed in <em>Radians</em>.</p>
 | 
| 
 | 
   145 </dd>
 | 
| 
 | 
   146 </dl>
 | 
| 
 | 
   147 <p>
 | 
| 
 | 
   148 </p>
 | 
| 
 | 
   149 <h2>AUTHOR</h2>
 | 
| 
 | 
   150 <p><a href="mailto:msud@san.rr.com">Manish Sud</a></p>
 | 
| 
 | 
   151 <p>
 | 
| 
 | 
   152 </p>
 | 
| 
 | 
   153 <h2>SEE ALSO</h2>
 | 
| 
 | 
   154 <p><a href="./Constants.html">Constants.pm</a>, <a href="./ConversionsUtil.html">ConversionsUtil.pm</a>
 | 
| 
 | 
   155 </p>
 | 
| 
 | 
   156 <p>
 | 
| 
 | 
   157 </p>
 | 
| 
 | 
   158 <h2>COPYRIGHT</h2>
 | 
| 
 | 
   159 <p>Copyright (C) 2015 Manish Sud. All rights reserved.</p>
 | 
| 
 | 
   160 <p>This file is part of MayaChemTools.</p>
 | 
| 
 | 
   161 <p>MayaChemTools is free software; you can redistribute it and/or modify it under
 | 
| 
 | 
   162 the terms of the GNU Lesser General Public License as published by the Free
 | 
| 
 | 
   163 Software Foundation; either version 3 of the License, or (at your option)
 | 
| 
 | 
   164 any later version.</p>
 | 
| 
 | 
   165 <p> </p><p> </p><div class="DocNav">
 | 
| 
 | 
   166 <table width="100%" border=0 cellpadding=0 cellspacing=2>
 | 
| 
 | 
   167 <tr align="left" valign="top"><td width="33%" align="left"><a href="./HTMLUtil.html" title="HTMLUtil.html">Previous</a>  <a href="./index.html" title="Table of Contents">TOC</a>  <a href="./Matrix.html" title="Matrix.html">Next</a></td><td width="34%" align="middle"><strong>March 29, 2015</strong></td><td width="33%" align="right"><strong>MathUtil.pm</strong></td></tr>
 | 
| 
 | 
   168 </table>
 | 
| 
 | 
   169 </div>
 | 
| 
 | 
   170 <br />
 | 
| 
 | 
   171 <center>
 | 
| 
 | 
   172 <img src="../../images/h2o2.png">
 | 
| 
 | 
   173 </center>
 | 
| 
 | 
   174 </body>
 | 
| 
 | 
   175 </html>
 |