예제 #1
0
파일: Cholesky.php 프로젝트: hoenirvili/cn
 /**
  * Get D - the diagonal matrix.
  * 
  * @return  matrix  D
  */
 public function getD()
 {
     $D = new Matrix($this->_matrix->rows(), $this->_matrix->columns());
     for ($i = 0; $i < $D->rows(); $i++) {
         $D->set($i, $i, $this->_matrix->get($i, $i));
     }
     return $D;
 }
예제 #2
0
파일: LU.php 프로젝트: hoenirvili/cn
 /**
  * Get the U of the decomposition.
  * 
  * @return  matrix  U
  */
 public function getU()
 {
     $U = $this->_matrix->copy();
     for ($i = 0; $i < $U->rows(); $i++) {
         for ($j = 0; $j < $i; $j++) {
             $U->set($i, $j, 0);
         }
     }
     return $U;
 }
예제 #3
0
 /**
  * Gets the upper triangular matrix R.
  */
 public function getR()
 {
     $R = $this->_matrix->copy();
     $n = min($R->rows(), $R->columns());
     for ($i = 0; $i < $R->rows(); $i++) {
         for ($j = 0; $j < $i and $j < $n; $j++) {
             $R->set($i, $j, 0);
         }
     }
     return $R;
 }
예제 #4
0
 /**
  *	QR Decomposition computed by Householder reflections.
  *
  *	@param matrix $A Rectangular matrix
  *	@return Structure to access R and the Householder vectors and compute Q.
  */
 public function __construct($A)
 {
     if ($A instanceof PHPExcel_Shared_JAMA_Matrix) {
         // Initialize.
         $this->QR = $A->getArrayCopy();
         $this->m = $A->getRowDimension();
         $this->n = $A->getColumnDimension();
         // Main loop.
         for ($k = 0; $k < $this->n; ++$k) {
             // Compute 2-norm of k-th column without under/overflow.
             $nrm = 0.0;
             for ($i = $k; $i < $this->m; ++$i) {
                 $nrm = hypo($nrm, $this->QR[$i][$k]);
             }
             if ($nrm != 0.0) {
                 // Form k-th Householder vector.
                 if ($this->QR[$k][$k] < 0) {
                     $nrm = -$nrm;
                 }
                 for ($i = $k; $i < $this->m; ++$i) {
                     $this->QR[$i][$k] /= $nrm;
                 }
                 $this->QR[$k][$k] += 1.0;
                 // Apply transformation to remaining columns.
                 for ($j = $k + 1; $j < $this->n; ++$j) {
                     $s = 0.0;
                     for ($i = $k; $i < $this->m; ++$i) {
                         $s += $this->QR[$i][$k] * $this->QR[$i][$j];
                     }
                     $s = -$s / $this->QR[$k][$k];
                     for ($i = $k; $i < $this->m; ++$i) {
                         $this->QR[$i][$j] += $s * $this->QR[$i][$k];
                     }
                 }
             }
             $this->Rdiag[$k] = -$nrm;
         }
     } else {
         throw new Exception(PHPExcel_Shared_JAMA_Matrix::ArgumentTypeException);
     }
 }
예제 #5
0
파일: QRGivens.php 프로젝트: hoenirvili/cn
 /**
  * Gets the upper triangular matrix R.
  */
 public function getR()
 {
     $R = $this->_matrix->copy();
     for ($i = 0; $i < $R->rows(); $i++) {
         for ($j = 0; $j < $i; $j++) {
             $R->set($i, $j, 0);
         }
     }
     // Resize R to a square matrix.
     $n = min($R->rows(), $R->columns());
     return $R->resize($n, $n);
 }
예제 #6
0
파일: Matrix.php 프로젝트: hoenirvili/cn
 /**
  * Add to matrices.
  *
  * @param   matrix  $a
  * @param   matrix  $b
  * @return  matrix  $a + $b
  */
 public static function add($a, $b)
 {
     new Assertion($a instanceof Matrix, 'Given first matrix not of class Matrix.');
     new Assertion($b instanceof Matrix, 'Given second matrix not of class Matrix.');
     new Assertion($a->rows() == $b->rows(), 'Given dimensions are not compatible.');
     new Assertion($a->columns() == $b->columns(), 'Given dimensions are not compatible.');
     $rows = $a->rows();
     $columns = $a->columns();
     $matrix = $a->copy();
     for ($i = 0; $i < $rows; $i++) {
         for ($j = 0; $j < $columns; $j++) {
             $matrix->set($i, $j, $matrix->get($i, $j) + $b->get($i, $j));
         }
     }
     return $matrix;
 }
예제 #7
0
        $i += 1;
    }
    /*menghitung rata-rata */
    $average_pegawai = mean($a);
    $average_barang = mean($b);
    $average_modal = mean($c);
    /*menghitung standar deviasi */
    $standard_deviation_pegawai = standard_deviation_population($a);
    $standard_deviation_barang = standard_deviation_population($b);
    $standard_deviation_modal = standard_deviation_population($c);
}
//while
$dataX = $ind;
$dataY = $tot;
$M = new matrix($dataX);
$X = $M->ArrayData;
$M = new matrix($dataY);
$Y = $M->ArrayData;
$Xt = $M->Transpose($X);
$XtX = $M->MultiplyMatrix($Xt, $X);
$XtY = $M->MultiplyMatrix($Xt, $Y);
$XtXi = $M->InverseMatrix($XtX);
$b = $M->MultiplyMatrix($XtXi, $XtY);
$usql = "update kelompok_kegiatan set " . "koefisien_1=" . (empty($b[1][0]) ? 'null' : sprintf("%01.3f", $b[1][0])) . ",koefisien_2=" . (empty($b[2][0]) ? 'null' : sprintf("%01.3f", $b[2][0])) . ",koefisien_3=" . (empty($b[3][0]) ? 'null' : sprintf("%01.3f", $b[3][0])) . ",koefisien_4=" . (empty($b[4][0]) ? 'null' : sprintf("%01.3f", $b[4][0])) . ",konstanta=" . (empty($b[0][0]) ? 'null' : sprintf("%01.3f", $b[0][0])) . ",rata_pegawai=" . (empty($average_pegawai) ? 'null' : sprintf("%01.3f", $average_pegawai)) . ",rata_barang=" . (empty($average_barang) ? 'null' : sprintf("%01.3f", $average_barang)) . ",rata_modal=" . (empty($average_modal) ? 'null' : sprintf("%01.3f", $average_modal)) . ",std_deviasi_pegawai=" . (empty($standard_deviation_pegawai) ? 'null' : sprintf("%01.3f", $standard_deviation_pegawai)) . ",std_deviasi_barang=" . (empty($standard_deviation_barang) ? 'null' : sprintf("%01.3f", $standard_deviation_barang)) . ",std_deviasi_modal=" . (empty($standard_deviation_modal) ? 'null' : sprintf("%01.3f", $standard_deviation_modal)) . " where id=" . $_REQUEST[gid];
gcms_query($usql);
echo $usql;
?>
 


예제 #8
0
 /**
  * Check norm of difference of "matrices".
  * @param matrix $X
  * @param matrix $Y
  */
 function checkMatrices($X = null, $Y = null)
 {
     if ($X == null || $Y == null) {
         return false;
     }
     $eps = pow(2.0, -52.0);
     if ($X->norm1() == 0.0 & $Y->norm1() < 10 * $eps) {
         return true;
     }
     if ($Y->norm1() == 0.0 & $X->norm1() < 10 * $eps) {
         return true;
     }
     $A = $X->minus($Y);
     if ($A->norm1() > 1000 * $eps * max($X->norm1(), $Y->norm1())) {
         die("The norm of (X-Y) is too large: " . $A->norm1());
     } else {
         return true;
     }
 }
예제 #9
0
        $clean_matrix = array();
        for ($i = 0; $i < count($matrix); $i++) {
            for ($j = 0; $j < count($matrix[$i]); $j++) {
                $clean_matrix[$i][$j] = clone $matrix[$i][$j];
            }
        }
        return $clean_matrix;
    }
    // If a solution found add it to the solution array
    private function addSolution($s)
    {
        array_push($this->solution, $s);
    }
    // getSolutions
    public function getSolution()
    {
        return $this->solution;
    }
}
// And fire the application
$matrixObj = new matrix();
$matrixObj->loopMatrix($matrix, false);
$solutions = $matrixObj->getSolution();
echo "Problem to solve: How many combinations are there which leads to a sum of 10? From every field you can go to a neighboring field: top, down, left, right and diagonal is allowed. <br />";
$matrixObj->printMatrix($matrix);
echo "<br />There are " . count($solutions) . " combinations which leads to a sum of 10.<br /><br />Solutions:<br />";
for ($i = 0; $i < count($solutions); $i++) {
    $clean_matrix = $matrixObj->cloneMatrix($matrix);
    echo '<br />' . ($i + 1) . '.';
    $matrixObj->printMatrix($clean_matrix, $solutions[$i]);
}
예제 #10
0
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" href="style.css" />
	<script src="jquery.min.js"></script>
	<script src="script.js"></script>
</head>
<body id="top">
	<h1>Лабораторная работа №1 по ДиВМ</h1>
	<a href="#new" id="set-new"><h2 <? if (isset($_POST['accept'])) {?>style="border-bottom-color:#036;"<? }?>>Задание новой СЛАУ</h2></a>
	<? if (isset($_POST['accept'])) {?><a href="#resh" id="set-resh"><h2>Решение СЛАУ</h2></a><? }?>
	<?
	if (isset($_POST['accept'])) {
		?>
		<div id="accept-cont">
			<div id="accept">
			<?
			$matr = new matrix($_POST['n-mer']);
			?>
			</div>
			<input type="button" id="hide-accept" value="Скрыть" class="button"> <input type="button" id="show-accept" value="Показать" class="button">
		</div>
		<?
	}
	?>
	<form action="" id="new" method="post" <? if (isset($_POST['accept'])) {?> style="display:none;"<? }?>>
		<label for="n-mer">Размерность матрицы:</label> <input name="n-mer" id="n-mer" type="number" min="1" value="3"> <input type="button" id="table_but" value="Сгенерировать матрицу" class="button"> <input type="button" id="gener_but" value="Заполнить случайными числами" class="button">
		<br>
		<label for="method">Выберите метод:</label>
		<select name="method">
			<option value="method_hauss" selected>1. Гаусса</option>
			<option value="method_holeck">2. Холецкого</option>
			<option value="method_zeidel">3. Зейделя</option>