Home >php教程 >php手册 >计算一个行列式的值

计算一个行列式的值

WBOY
WBOYOriginal
2016-06-06 19:38:522142browse

php计算行列式的值,参数为数组和阶数,返回值为行列式的值,求解多元一次方程组时肯定会用到 无 ?phpclass Hanglieshi{//行列式计算public function jisuan($arr,$num){$num--;for ($k=0; $k $num; $k++) { for ($i=$k; $i $num; $i++) { $temp=$arr[$i+1][$

php计算行列式的值,参数为数组和阶数,返回值为行列式的值,求解多元一次方程组时肯定会用到
<?php
class Hanglieshi{
	//行列式计算
	public function jisuan($arr,$num){
			$num--;
			
			for ($k=0; $k < $num; $k++) { 
				for ($i=$k; $i < $num; $i++) { 
					$temp=$arr[$i+1][$k];
					$arr[$i+1][$k]=0;
					for ($j=$k+1; $j <= $num; $j++) { 
						if($arr[$k][$k]!=0){
							$arr[$i+1][$j]=$arr[$i+1][$j]-($temp/$arr[$k][$k])*$arr[$k][$j];
						}else{
							$arr[$k][$k]=0.00000000000001;	//误差精度控制
							$arr[$i+1][$j]=$arr[$i+1][$j]-($temp/$arr[$k][$k])*$arr[$k][$j];
						}
					}
				}
			}

			//计算返回值
			$result=1.0;
			for ($n=0; $n <= $num; $n++) { 
				$result*=$arr[$n][$n];
			}
			return $result;
	}
}
?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article://获取网页中的所有链接Next article:dns查询压测