📄 householderqrdecomposer.java
字号:
package org.jutil.math.matrix;/** * <p>A class of objects that compute the QR factorization of a matrix using * the Householder Algorithm.</p> * * @path $Source: /cvsroot/org-jutil/jutil.org/src/org/jutil/math/matrix/HouseholderQRDecomposer.java,v $ * @version $Revision: 1.3 $ * @date $Date: 2002/05/20 15:01:37 $ * @state $State: Exp $ * @author Marko van Dooren * @release $Name: $ */public class HouseholderQRDecomposer implements QRDecomposer { /* The revision of this class */ public final static String CVS_REVISION ="$Revision: 1.3 $"; /** * <p>The decomposition is done using the Householder algorithm.</p> * <p>The algorithmic complexity is <b>O(2mn^2 - (2/3)n^3)</b>.</p> */ public QRDecomposition decompose(Matrix matrix) { Matrix R = (Matrix) matrix.clone(); int columns = matrix.getNbColumns(); int rows = matrix.getNbRows(); Column[] vs = new Column[columns]; for (int k=1; k<=columns; k++) { Column x = R.getColumn(k).subColumn(k, rows); Column v = new Column(rows - k + 1); double x1 = x.elementAt(1); double signX1 = org.jutil.math.Math.sign(x1); v.setElementAt(1,x.norm(2)*signX1); v.add(x); v.normalize(); vs[k-1]=v; Matrix A = R.subMatrix(k,k,rows,columns); // subtracting from A saves us a clone() // mutating temp saves us another one ( <-> .times(2)) Matrix temp = v.times(v.returnTranspose().times(A)); temp.multiply(2); A.subtract(temp); R.setSubMatrix(k,k,A); } // explicitly make R an upper triangular matrix. for(int col=1; col<=columns; col++) { for(int row=col+1; row<=rows; row++) { R.setElementAt(row,col,0); } } return new HouseholderQRDecomposition(R,vs); }}/*<copyright>Copyright (C) 1997-2002. This software is copyrighted by the people and entities mentioned after the "@author" tags above, on behalf of the JUTIL.ORG Project. The copyright is dated by the dates after the "@date" tags above. All rights reserved.This software is published under the terms of the JUTIL.ORG SoftwareLicense version 1.1 or later, a copy of which has been included withthis distribution in the LICENSE file, which can also be found athttp://www.jutil.org/LICENSE. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the JUTIL.ORG Software License for more details.For more information, please see http://jutil.org/</copyright>*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -