当前位置: 首页>>代码示例>>PHP>>正文


PHP JAMAError函数代码示例

本文整理汇总了PHP中JAMAError函数的典型用法代码示例。如果您正苦于以下问题:PHP JAMAError函数的具体用法?PHP JAMAError怎么用?PHP JAMAError使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了JAMAError函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: times

 /**
  *    times
  *
  *    Matrix multiplication
  *    @param mixed $n Matrix/Array/Scalar
  *    @return Matrix Product
  */
 public function times()
 {
     if (func_num_args() > 0) {
         $args = func_get_args();
         $match = implode(",", array_map('gettype', $args));
         switch ($match) {
             case 'object':
                 if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) {
                     $B = $args[0];
                 } else {
                     throw new PHPExcel_Calculation_Exception(self::ARGUMENT_TYPE_EXCEPTION);
                 }
                 if ($this->n == $B->m) {
                     $C = new PHPExcel_Shared_JAMA_Matrix($this->m, $B->n);
                     for ($j = 0; $j < $B->n; ++$j) {
                         for ($k = 0; $k < $this->n; ++$k) {
                             $Bcolj[$k] = $B->A[$k][$j];
                         }
                         for ($i = 0; $i < $this->m; ++$i) {
                             $Arowi = $this->A[$i];
                             $s = 0;
                             for ($k = 0; $k < $this->n; ++$k) {
                                 $s += $Arowi[$k] * $Bcolj[$k];
                             }
                             $C->A[$i][$j] = $s;
                         }
                     }
                     return $C;
                 } else {
                     throw new PHPExcel_Calculation_Exception(JAMAError(MatrixDimensionMismatch));
                 }
                 break;
             case 'array':
                 $B = new PHPExcel_Shared_JAMA_Matrix($args[0]);
                 if ($this->n == $B->m) {
                     $C = new PHPExcel_Shared_JAMA_Matrix($this->m, $B->n);
                     for ($i = 0; $i < $C->m; ++$i) {
                         for ($j = 0; $j < $C->n; ++$j) {
                             $s = "0";
                             for ($k = 0; $k < $C->n; ++$k) {
                                 $s += $this->A[$i][$k] * $B->A[$k][$j];
                             }
                             $C->A[$i][$j] = $s;
                         }
                     }
                     return $C;
                 } else {
                     throw new PHPExcel_Calculation_Exception(JAMAError(MatrixDimensionMismatch));
                 }
                 return $M;
                 break;
             case 'integer':
                 $C = new PHPExcel_Shared_JAMA_Matrix($this->A);
                 for ($i = 0; $i < $C->m; ++$i) {
                     for ($j = 0; $j < $C->n; ++$j) {
                         $C->A[$i][$j] *= $args[0];
                     }
                 }
                 return $C;
                 break;
             case 'double':
                 $C = new PHPExcel_Shared_JAMA_Matrix($this->m, $this->n);
                 for ($i = 0; $i < $C->m; ++$i) {
                     for ($j = 0; $j < $C->n; ++$j) {
                         $C->A[$i][$j] = $args[0] * $this->A[$i][$j];
                     }
                 }
                 return $C;
                 break;
             case 'float':
                 $C = new PHPExcel_Shared_JAMA_Matrix($this->A);
                 for ($i = 0; $i < $C->m; ++$i) {
                     for ($j = 0; $j < $C->n; ++$j) {
                         $C->A[$i][$j] *= $args[0];
                     }
                 }
                 return $C;
                 break;
             default:
                 throw new PHPExcel_Calculation_Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION);
                 break;
         }
     } else {
         throw new PHPExcel_Calculation_Exception(self::POLYMORPHIC_ARGUMENT_EXCEPTION);
     }
 }
开发者ID:alyayazilim,项目名称:E-Ticaret-2015,代码行数:93,代码来源:Matrix.php

示例2: concat

 /**
  *	concat
  *
  *	A = A & B
  *	@param mixed $B Matrix/Array
  *	@return Matrix Sum
  */
 public function concat()
 {
     if (func_num_args() > 0) {
         $args = func_get_args();
         $match = implode(",", array_map('gettype', $args));
         switch ($match) {
             case 'object':
                 if ($args[0] instanceof Matrix) {
                     $M = $args[0];
                 } else {
                     throw new Exception(JAMAError(ArgumentTypeException));
                 }
             case 'array':
                 $M = new Matrix($args[0]);
                 break;
             default:
                 throw new Exception(JAMAError(PolymorphicArgumentException));
                 break;
         }
         $this->checkMatrixDimensions($M);
         for ($i = 0; $i < $this->m; ++$i) {
             for ($j = 0; $j < $this->n; ++$j) {
                 //					$this->A[$i][$j] = '"'.trim($this->A[$i][$j],'"').trim($M->get($i, $j),'"').'"';
                 $this->A[$i][$j] = trim($this->A[$i][$j], '"') . trim($M->get($i, $j), '"');
             }
         }
         return $this;
     } else {
         throw new Exception(JAMAError(PolymorphicArgumentException));
     }
 }
开发者ID:bestgoodz,项目名称:toko-baju,代码行数:38,代码来源:Matrix.php

示例3: solve

 /**
  *	Solve A*X = B
  *
  *	@param $B Row-equal matrix
  *	@return Matrix L * L' * X = B
  */
 public function solve($B = null)
 {
     if ($B instanceof Matrix) {
         if ($B->getRowDimension() == $this->m) {
             if ($this->isspd) {
                 $X = $B->getArrayCopy();
                 $nx = $B->getColumnDimension();
                 for ($k = 0; $k < $this->m; ++$k) {
                     for ($i = $k + 1; $i < $this->m; ++$i) {
                         for ($j = 0; $j < $nx; ++$j) {
                             $X[$i][$j] -= $X[$k][$j] * $this->L[$i][$k];
                         }
                     }
                     for ($j = 0; $j < $nx; ++$j) {
                         $X[$k][$j] /= $this->L[$k][$k];
                     }
                 }
                 for ($k = $this->m - 1; $k >= 0; --$k) {
                     for ($j = 0; $j < $nx; ++$j) {
                         $X[$k][$j] /= $this->L[$k][$k];
                     }
                     for ($i = 0; $i < $k; ++$i) {
                         for ($j = 0; $j < $nx; ++$j) {
                             $X[$i][$j] -= $X[$k][$j] * $this->L[$k][$i];
                         }
                     }
                 }
                 return new Matrix($X, $this->m, $nx);
             } else {
                 throw new Exception(JAMAError(MatrixSPDException));
             }
         } else {
             throw new Exception(JAMAError(MatrixDimensionException));
         }
     } else {
         throw new Exception(JAMAError(ArgumentTypeException));
     }
 }
开发者ID:linhanwei,项目名称:TP,代码行数:44,代码来源:CholeskyDecomposition.php

示例4: solve

 /**
  *	Least squares solution of A*X = B
  *
  *	@param Matrix $B A Matrix with as many rows as A and any number of columns.
  *	@return Matrix Matrix that minimizes the two norm of Q*R*X-B.
  */
 public function solve($B)
 {
     if ($B->getRowDimension() == $this->m) {
         if ($this->isFullRank()) {
             // Copy right hand side
             $nx = $B->getColumnDimension();
             $X = $B->getArrayCopy();
             // Compute Y = transpose(Q)*B
             for ($k = 0; $k < $this->n; ++$k) {
                 for ($j = 0; $j < $nx; ++$j) {
                     $s = 0.0;
                     for ($i = $k; $i < $this->m; ++$i) {
                         $s += $this->QR[$i][$k] * $X[$i][$j];
                     }
                     $s = -$s / $this->QR[$k][$k];
                     for ($i = $k; $i < $this->m; ++$i) {
                         $X[$i][$j] += $s * $this->QR[$i][$k];
                     }
                 }
             }
             // Solve R*X = Y;
             for ($k = $this->n - 1; $k >= 0; --$k) {
                 for ($j = 0; $j < $nx; ++$j) {
                     $X[$k][$j] /= $this->Rdiag[$k];
                 }
                 for ($i = 0; $i < $k; ++$i) {
                     for ($j = 0; $j < $nx; ++$j) {
                         $X[$i][$j] -= $X[$k][$j] * $this->QR[$i][$k];
                     }
                 }
             }
             $X = new Matrix($X);
             return $X->getMatrix(0, $this->n - 1, 0, $nx);
         } else {
             throw new Exception(JAMAError(MatrixRankException));
         }
     } else {
         throw new Exception(JAMAError(MatrixDimensionException));
     }
 }
开发者ID:linhanwei,项目名称:TP,代码行数:46,代码来源:QRDecomposition.php

示例5: solve

 /**
  *    Solve A*X = B
  *
  *    @param $B Row-equal matrix
  *    @return Matrix L * L' * X = B
  */
 public function solve($B = null)
 {
     if ($B instanceof Matrix) {
         if ($B->getRowDimension() == $this->m) {
             if ($this->isspd) {
                 $X = $B->getArrayCopy();
                 $nx = $B->getColumnDimension();
                 for ($k = 0; $k < $this->m; ++$k) {
                     for ($i = $k + 1; $i < $this->m; ++$i) {
                         for ($j = 0; $j < $nx; ++$j) {
                             $X[$i][$j] -= $X[$k][$j] * $this->L[$i][$k];
                         }
                     }
                     for ($j = 0; $j < $nx; ++$j) {
                         $X[$k][$j] /= $this->L[$k][$k];
                     }
                 }
                 for ($k = $this->m - 1; $k >= 0; --$k) {
                     for ($j = 0; $j < $nx; ++$j) {
                         $X[$k][$j] /= $this->L[$k][$k];
                     }
                     for ($i = 0; $i < $k; ++$i) {
                         for ($j = 0; $j < $nx; ++$j) {
                             $X[$i][$j] -= $X[$k][$j] * $this->L[$k][$i];
                         }
                     }
                 }
                 return new Matrix($X, $this->m, $nx);
             } else {
                 throw new PHPExcel_Calculation_Exception(JAMAError(MatrixSPDException));
             }
         } else {
             throw new PHPExcel_Calculation_Exception(JAMAError(MATRIX_DIMENSION_EXCEPTION));
         }
     } else {
         throw new PHPExcel_Calculation_Exception(JAMAError(ARGUMENT_TYPE_EXCEPTION));
     }
 }
开发者ID:alyayazilim,项目名称:E-Ticaret-2015,代码行数:44,代码来源:CholeskyDecomposition.php

示例6: solve

 /**
  *	Solve A*X = B
  *
  *	@param  $B  A Matrix with as many rows as A and any number of columns.
  *	@return  X so that L*U*X = B(piv,:)
  *	@exception  IllegalArgumentException Matrix row dimensions must agree.
  *	@exception  RuntimeException  Matrix is singular.
  */
 public function solve($B)
 {
     if ($B->getRowDimension() == $this->m) {
         if ($this->isNonsingular()) {
             // Copy right hand side with pivoting
             $nx = $B->getColumnDimension();
             $X = $B->getMatrix($this->piv, 0, $nx - 1);
             // Solve L*Y = B(piv,:)
             for ($k = 0; $k < $this->n; ++$k) {
                 for ($i = $k + 1; $i < $this->n; ++$i) {
                     for ($j = 0; $j < $nx; ++$j) {
                         $X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k];
                     }
                 }
             }
             // Solve U*X = Y;
             for ($k = $this->n - 1; $k >= 0; --$k) {
                 for ($j = 0; $j < $nx; ++$j) {
                     $X->A[$k][$j] /= $this->LU[$k][$k];
                 }
                 for ($i = 0; $i < $k; ++$i) {
                     for ($j = 0; $j < $nx; ++$j) {
                         $X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k];
                     }
                 }
             }
             return $X;
         } else {
             throw new Exception(JAMAError(MatrixSingularException));
         }
     } else {
         throw new Exception(JAMAError(MatrixSquareException));
     }
 }
开发者ID:kumarsivarajan,项目名称:ctrl-dock,代码行数:42,代码来源:LUDecomposition.php


注:本文中的JAMAError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。