Home > php教程 > php手册 > body text

计算一个行列式的值

WBOY
Release: 2016-06-06 19:38:52
Original
2089 people have browsed it

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;
	}
}
?>
Copy after login
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!