Latest recipes tagged "determinants"http://code.activestate.com/recipes/tags/determinants/new/2012-08-07T08:45:23-07:00ActiveState Code RecipesAlternatve 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>
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>
Silmultaneous linear equation solver(any order) (Python)
2012-04-24T12:29:30-07:00Sachin Joglekarhttp://code.activestate.com/recipes/users/4181845/http://code.activestate.com/recipes/578109-silmultaneous-linear-equation-solverany-order/
<p style="color: grey">
Python
recipe 578109
by <a href="/recipes/users/4181845/">Sachin Joglekar</a>
(<a href="/recipes/tags/algebra/">algebra</a>, <a href="/recipes/tags/crammer/">crammer</a>, <a href="/recipes/tags/determinants/">determinants</a>, <a href="/recipes/tags/equation/">equation</a>, <a href="/recipes/tags/linear/">linear</a>, <a href="/recipes/tags/simultaneous/">simultaneous</a>).
</p>
<p>Solves simultaneous linear equations of any order using Crammer's rule. Required input is two lists..one for coefficients, and other for constants
eg. 2x+3y=8
x+4y=6 will be written as
simul([[2,3],[1,4]],[8,6])</p>