Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-14 09:15:08

0001 // Created on: 1991-08-07
0002 // Created by: Laurent PAINNOT
0003 // Copyright (c) 1991-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _math_Householder_HeaderFile
0018 #define _math_Householder_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <math_Matrix.hxx>
0025 #include <math_Vector.hxx>
0026 #include <Standard_OStream.hxx>
0027 
0028 //! This class implements the least square solution of a set of
0029 //! linear equations of m unknowns (n >= m) using the Householder
0030 //! method. It solves A.X = B.
0031 //! This algorithm has more numerical stability than
0032 //! GaussLeastSquare but is longer.
0033 //! It must be used if the matrix is singular or nearly singular.
0034 //! It is about 16% longer than GaussLeastSquare if there is only
0035 //! one member B to solve.
0036 //! It is about 30% longer if there are twenty B members to solve.
0037 class math_Householder
0038 {
0039 public:
0040   DEFINE_STANDARD_ALLOC
0041 
0042   //! Given an input matrix A with n>= m, given an input matrix B
0043   //! this constructor performs the least square resolution of
0044   //! the set of linear equations A.X = B for each column of B.
0045   //! If a column norm is less than EPS, the resolution can't
0046   //! be done.
0047   //! Exception DimensionError is raised if the row number of B
0048   //! is different from the A row number.
0049   Standard_EXPORT math_Householder(const math_Matrix& A,
0050                                    const math_Matrix& B,
0051                                    const double       EPS = 1.0e-20);
0052 
0053   //! Given an input matrix A with n>= m, given an input matrix B
0054   //! this constructor performs the least square resolution of
0055   //! the set of linear equations A.X = B for each column of B.
0056   //! If a column norm is less than EPS, the resolution can't
0057   //! be done.
0058   //! Exception DimensionError is raised if the row number of B
0059   //! is different from the A row number.
0060   Standard_EXPORT math_Householder(const math_Matrix& A,
0061                                    const math_Matrix& B,
0062                                    const int          lowerArow,
0063                                    const int          upperArow,
0064                                    const int          lowerAcol,
0065                                    const int          upperAcol,
0066                                    const double       EPS = 1.0e-20);
0067 
0068   //! Given an input matrix A with n>= m, given an input vector B
0069   //! this constructor performs the least square resolution of
0070   //! the set of linear equations A.X = B.
0071   //! If a column norm is less than EPS, the resolution can't
0072   //! be done.
0073   //! Exception DimensionError is raised if the length of B
0074   //! is different from the A row number.
0075   Standard_EXPORT math_Householder(const math_Matrix& A,
0076                                    const math_Vector& B,
0077                                    const double       EPS = 1.0e-20);
0078 
0079   //! Returns true if the computations are successful, otherwise returns false.
0080   bool IsDone() const;
0081 
0082   //! Given the integer Index, this routine returns the
0083   //! corresponding least square solution sol.
0084   //! Exception NotDone is raised if the resolution has not be
0085   //! done.
0086   //! Exception OutOfRange is raised if Index <=0 or
0087   //! Index is more than the number of columns of B.
0088   void Value(math_Vector& sol, const int Index = 1) const;
0089 
0090   //! Returns the matrix sol of all the solutions of the system
0091   //! A.X = B.
0092   //! Exception NotDone is raised is the resolution has not be
0093   //! done.
0094   const math_Matrix& AllValues() const;
0095 
0096   //! Prints information on the current state of the object.
0097   Standard_EXPORT void Dump(Standard_OStream& o) const;
0098 
0099 protected:
0100   //! This method is used internally for each constructor
0101   //! above and can't be used directly.
0102   Standard_EXPORT void Perform(const math_Matrix& A, const math_Matrix& B, const double EPS);
0103 
0104 private:
0105   math_Matrix Sol;
0106   math_Matrix Q;
0107   bool        Done;
0108   int         mylowerArow;
0109   int         myupperArow;
0110   int         mylowerAcol;
0111   int         myupperAcol;
0112 };
0113 
0114 #include <math_Householder.lxx>
0115 
0116 #endif // _math_Householder_HeaderFile