cooldude832 Posted October 23, 2007 Share Posted October 23, 2007 I know it could be done, but image a 20x20 matrix, that is a ton of minors to do, anyone got an idea on discovering the most 0ed row/column to expand upon. The expansion is fairly easily, but I was wondering if it could be made faster by finding the path of least resistance, or if that is just a waste of power? Quote Link to comment https://forums.phpfreaks.com/topic/74409-solving-determinates-in-php/ Share on other sites More sharing options...
Orio Posted October 23, 2007 Share Posted October 23, 2007 You could do something like this- it chooses the most 0ed column/row and from there you can continue. <?php //$matrix is a ($matrix_size)X($matrix_size) matrix $matrix_size = 20; $max1 = $max1_v = 0; $max2 = $max2_v = 0; $transpose = array(); for($i=0; $i<$matrix_size; $i++) for($j=0; $j<$matrix_size; $j++) $transpose[$j][$i] = $matrix[$i][$j]; for($i=0; $i<$matrix_size; $i++) if ($max1_v < $temp=count(array_keys($matrix[$i], 0))) { $max1_v = $temp; $max1 = $i; } for($i=0; $i<$matrix_size; $i++) { if ($max2_v < $temp=count(array_keys($transpose[$i], 0))) { $max2_v = $temp; $max2 = $i; } } if($max1_v < $max2_v) //Remember- the output is between 0 to ($matrix_size-1) echo "Use column $max2"; else echo "Use row $max1"; ?> Orio. Quote Link to comment https://forums.phpfreaks.com/topic/74409-solving-determinates-in-php/#findComment-376059 Share on other sites More sharing options...
sasa Posted October 23, 2007 Share Posted October 23, 2007 try <?php function deter($a, $i = -1){ if ($i < 0) $i = count($a) -1; if ($i==0) return $a[0][0]; $j = $i; $sig = 1; while ($a[$j][$i] == 0 and $j-- > -1); if ($i != $j and $a[$j][$i] != 0) { $tmp = $a[$i]; $a[$i] = $a[$j]; $a[$j] = $tmp; $sig *= -1; } else if($a[$j][$i] == 0) return 0; $b = $a[$i][$i]; for ($row = $i -1; $row >= 0; $row--){ $c = -$a[$row][$i] / $b; for ($k = 0; $k < $i; $k++){ $a[$row][$k] += $a[$i][$k] * $c; } } return $out = $b * deter($a, $i - 1) * $sig; } $matr = array( array(0,2,0), array(3,4,2), array(6,0,0) ); echo deter($matr); ?> Quote Link to comment https://forums.phpfreaks.com/topic/74409-solving-determinates-in-php/#findComment-376137 Share on other sites More sharing options...
corbin Posted October 23, 2007 Share Posted October 23, 2007 Whoa.... We did that in Algebra 2 the other day (I'm in 10th grade lol).... Hmmm would diagonals or minors be faster PHP wise.... I guess minors would be since it would be a lot less math (especially with 20x20 matrices and what not).... Bleh idk.... Hmmm.... I contributed nothing to this thread.... oh well ;p. Quote Link to comment https://forums.phpfreaks.com/topic/74409-solving-determinates-in-php/#findComment-376524 Share on other sites More sharing options...
cooldude832 Posted October 23, 2007 Author Share Posted October 23, 2007 yeah you learn them early, but my application to them is figuring out linear dependencies of non-first order diffy Qs, so your education now will help later. Quote Link to comment https://forums.phpfreaks.com/topic/74409-solving-determinates-in-php/#findComment-376626 Share on other sites More sharing options...
corbin Posted October 23, 2007 Share Posted October 23, 2007 I don't even know what a non-first order differential equation is lol..... (Guess that's what the abbreviations were ;p) Quote Link to comment https://forums.phpfreaks.com/topic/74409-solving-determinates-in-php/#findComment-376630 Share on other sites More sharing options...
cooldude832 Posted October 23, 2007 Author Share Posted October 23, 2007 abbrivations??? Quote Link to comment https://forums.phpfreaks.com/topic/74409-solving-determinates-in-php/#findComment-376652 Share on other sites More sharing options...
Barand Posted October 24, 2007 Share Posted October 24, 2007 No, abbreviations As in diffy Qs Quote Link to comment https://forums.phpfreaks.com/topic/74409-solving-determinates-in-php/#findComment-376661 Share on other sites More sharing options...
cooldude832 Posted October 24, 2007 Author Share Posted October 24, 2007 Diffy as in Differential thought that was pretty straight forward. Quote Link to comment https://forums.phpfreaks.com/topic/74409-solving-determinates-in-php/#findComment-376672 Share on other sites More sharing options...
Barand Posted October 24, 2007 Share Posted October 24, 2007 I agree completely. Most of us would have thought the term "abbrivations abbreviations" pretty straightforward too, so why query it, having just abbreviated "differential equations" to "diffy Qs" All corbin wanted was confirmation that that was what you meant. Quote Link to comment https://forums.phpfreaks.com/topic/74409-solving-determinates-in-php/#findComment-376679 Share on other sites More sharing options...
corbin Posted October 24, 2007 Share Posted October 24, 2007 lol just curious if I guessed that right since that sounded oddly familiar.... No idea why though.... haha... Didn't mean to start a discussion about it ;p. Quote Link to comment https://forums.phpfreaks.com/topic/74409-solving-determinates-in-php/#findComment-376705 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.