PHP 역행렬
답변
너는 이것을 위해 배 패키지 Math_Matrix을 사용할 수 있습니다.
이 package claims 당신이 찾고있는 것을 할 수 있습니다.
매트릭스를 뒤집을 수있는 오픈 소스 PHP Library이 있습니다.
당신이해야 할 모든
은<?php
include_once ("Matrix.class.php");
$matrixA = new Matrix(array(array(0, 1), array(2, 6)));
echo $matrixA->getInverse()->getMathMl();
?>
/**
* matrix_inverse
*
* Matrix Inverse
* Guass-Jordan Elimination Method
* Reduced Row Eshelon Form (RREF)
*
* In linear algebra an n-by-n (square) matrix A is called invertible (some
* authors use nonsingular or nondegenerate) if there exists an n-by-n matrix B
* such that AB = BA = In where In denotes the n-by-n identity matrix and the
* multiplication used is ordinary matrix multiplication. If this is the case,
* then the matrix B is uniquely determined by A and is called the inverse of A,
* denoted by A-1. It follows from the theory of matrices that if for finite
* square matrices A and B, then also non-square matrices (m-by-n matrices for
* which m ? n) do not have an inverse. However, in some cases such a matrix may
* have a left inverse or right inverse. If A is m-by-n and the rank of A is
* equal to n, then A has a left inverse: an n-by-m matrix B such that BA = I.
* If A has rank m, then it has a right inverse: an n-by-m matrix B such that
* AB = I.
*
* A square matrix that is not invertible is called singular or degenerate. A
* square matrix is singular if and only if its determinant is 0. Singular
* matrices are rare in the sense that if you pick a random square matrix over
* a continuous uniform distribution on its entries, it will almost surely not
* be singular.
*
* While the most common case is that of matrices over the real or complex
* numbers, all these definitions can be given for matrices over any commutative
* ring. However, in this case the condition for a square matrix to be
* invertible is that its determinant is invertible in the ring, which in
* general is a much stricter requirement than being nonzero. The conditions for
* existence of left-inverse resp. right-inverse are more complicated since a
* notion of rank does not exist over rings.
*/
public function matrix_inverse($m1)
{
$rows = $this->rows($m1);
$cols = $this->columns($m1);
if ($rows != $cols)
{
die("Matrim1 is not square. Can not be inverted.");
}
$m2 = $this->eye($rows);
for ($j = 0; $j < $cols; $j++)
{
$factor = $m1[$j][$j];
if ($this->debug)
{
fms_writeln('Divide Row [' . $j . '] by ' . $m1[$j][$j] . ' (to
give us a "1" in the desired position):');
}
$m1 = $this->rref_div($m1, $j, $factor);
$m2 = $this->rref_div($m2, $j, $factor);
if ($this->debug)
{
$this->disp2($m1, $m2);
}
for ($i = 0; $i < $rows; $i++)
{
if ($i != $j)
{
$factor = $m1[$i][$j];
if ($this->debug)
{
$this->writeln('Row[' . $i . '] - ' . number_format($factor, 4) . ' ×
Row[' . $j . '] (to give us 0 in the desired position):');
}
$m1 = $this->rref_sub($m1, $i, $factor, $j);
$m2 = $this->rref_sub($m2, $i, $factor, $j);
if ($this->debug)
{
$this->disp2($m1, $m2);
}
}
}
}
return $m2;
}
이 코드는 절대 표시되지 않는'$ this'에있는 함수에 대한 간단한 참조를 가지고 있습니다. 이 컨텍스트가 없으면 코드는 불행히도 쓸모가 없습니다. –
다음은 테스트 코드 https://gist.github.com/unix1/7510208 만 identity_matrix()와 반전() 함수가 충분히
라이브러리가 더 이상 사용 가능하지 않은 것 같습니다 –
@MarkBaker 명확하게 사용할 수 있습니다. 요지는 항상 공개되었으며 그 위치는 2013 년 11 월부터였습니다. 면책 조항 : 저는 그 요지의 저자입니다. –
을하고 있는지 링크 페이지를 생성하지 않습니다이다. – monksy
와우. 배 페이지는 실제로 그 링크를 좋아하지 않습니다. 거기에 가서 링크를 바로 잡으려고했습니다. 같은 문제. 직접 링크 할 수 없습니다. 최상위 메뉴에서 패키지 검색을 클릭하고 행렬 –
을 검색하면 올바른 링크는 pear.php.net/package/Math-Matrix 입니다. (죄송하지만 편집하여 게시물을 수정하여 제 위치의 링크를 수정하십시오.) – Eineki