1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

Integration of OCCT 6.5.0 from SVN

This commit is contained in:
bugmaster
2011-03-16 07:30:28 +00:00
committed by bugmaster
parent 4903637061
commit 7fd59977df
16375 changed files with 3882564 additions and 0 deletions

6
src/math/FILES Executable file
View File

@@ -0,0 +1,6 @@
math_Memory.cxx
math_Recipes.cxx
math_Memory.hxx
math_Recipes.hxx
math_GaussPoints.hxx
math_Kronrod.cxx

142
src/math/math.cdl Executable file
View File

@@ -0,0 +1,142 @@
---- File: math.cdl
-- Created: Mon Jan 21 14:19:01 1991
-- Author: Isabelle GRIGNON
-- <isg@topsn3>
-- Modified by PMN 29/02/96: GaussSetIntegration added
-- Modified by PMN 03/05/96: NewtonMinimum added
---Copyright: Matra Datavision 1991-1996
package math
uses StdFail, TColStd, TCollection, Standard, SortTools
is
---Level : Public
-- All methods of all classes of this package will be public.
enumeration Status is
OK,
TooManyIterations,
FunctionError,
DirectionSearchError,
NotBracketed
end Status;
exception NotSquare inherits DimensionError;
exception SingularMatrix inherits Failure;
class Vector;
class IntegerVector;
class Matrix;
deferred class Function;
deferred class FunctionWithDerivative;
deferred class MultipleVarFunction;
deferred class MultipleVarFunctionWithGradient;
deferred class MultipleVarFunctionWithHessian;
deferred class FunctionSet;
deferred class FunctionSetWithDerivatives;
class IntegerRandom;
class Gauss;
class GaussLeastSquare;
class SVD;
class DirectPolynomialRoots;
class FunctionRoots;
class BissecNewton;
class FunctionRoot;
class NewtonFunctionRoot;
class BracketedRoot;
class FunctionSetRoot;
class NewtonFunctionSetRoot;
class BracketMinimum;
class BrentMinimum;
class Powell;
class FRPR;
class BFGS;
class NewtonMinimum;
class Jacobi;
class GaussSingleIntegration;
class GaussMultipleIntegration;
class GaussSetIntegration;
class RealRandom;
class FunctionSample;
class FunctionAllRoots;
class Householder;
class Crout;
class Uzawa;
class TrigonometricFunctionRoots;
class KronrodSingleIntegration; -- SKV: Kronrod method implementation.
class EigenValuesSearcher; -- for Kronrod method
class ComputeGaussPointsAndWeights;
class ComputeKronrodPointsAndWeights;
class ValueAndWeight;
class Array1OfValueAndWeight
instantiates Array1 from TCollection (ValueAndWeight from math);
class CompareOfValueAndWeight;
class QuickSortOfValueAndWeight
instantiates QuickSort from SortTools (ValueAndWeight from math,
Array1OfValueAndWeight from math,
CompareOfValueAndWeight from math);
generic class SingleTab;
generic class DoubleTab;
--- Instantiate classes:
class SingleTabOfReal instantiates SingleTab(Real);
class SingleTabOfInteger instantiates SingleTab(Integer);
class DoubleTabOfReal instantiates DoubleTab(Real);
--- Gauss Points
GaussPointsMax returns Integer;
GaussPoints(Index : Integer; Points : out Vector from math);
GaussWeights(Index : Integer; Weights : out Vector from math);
-- Modified by skv - Wed Dec 7 15:32:31 2005 Kronrod method. Begin
KronrodPointsMax returns Integer;
---Purpose: Returns the maximal number of points for that the values
-- are stored in the table. If the number is greater then
-- KronrodPointsMax, the points will be computed.
OrderedGaussPointsAndWeights(Index : Integer;
Points : out Vector from math;
Weights : out Vector from math)
---Purpose: Returns a vector of Gauss points and a vector of their weights.
-- The difference with the
-- method GaussPoints is the following:
-- - the points are returned in increasing order.
-- - if Index is greater then GaussPointsMax, the points are
-- computed.
-- Returns Standard_True if Index is positive, Points' and Weights'
-- length is equal to Index, Points and Weights are successfully computed.
returns Boolean from Standard;
KronrodPointsAndWeights(Index : Integer;
Points : out Vector from math;
Weights : out Vector from math)
---Purpose: Returns a vector of Kronrod points and a vector of their
-- weights for Gauss-Kronrod computation method.
-- Index should be odd and greater then or equal to 3,
-- as the number of Kronrod points is equal to 2*N + 1,
-- where N is a number of Gauss points. Points and Weights should
-- have the size equal to Index. Each even element of Points
-- represents a Gauss point value of N-th Gauss quadrature.
-- The values from Index equal to 3 to 123 are stored in a
-- table (see the file math_Kronrod.cxx). If Index is greater,
-- then points and weights will be computed. Returns Standard_True
-- if Index is odd, it is equal to the size of Points and Weights
-- and the computation of Points and Weights is performed successfully.
-- Otherwise this method returns Standard_False.
returns Boolean from Standard;
-- Modified by skv - Wed Dec 7 15:32:31 2005 Kronrod method. End
end math;

2041
src/math/math.cxx Executable file

File diff suppressed because it is too large Load Diff

165
src/math/math_BFGS.cdl Executable file
View File

@@ -0,0 +1,165 @@
-- File: BFGS.cdl
-- Created: Tue May 14 16:01:21 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class BFGS from math
---Purpose:
-- This class implements the Broyden-Fletcher-Goldfarb-Shanno variant of
-- Davidson-Fletcher-Powell minimization algorithm of a function of
-- multiple variables.Knowledge of the function's gradient is required.
uses Vector from math, Matrix from math,
MultipleVarFunctionWithGradient from math,
Status from math,
OStream from Standard
raises NotDone from StdFail,
DimensionError from Standard
is
Create(F: in out MultipleVarFunctionWithGradient;
StartingPoint: Vector; Tolerance: Real=1.0e-8;
NbIterations: Integer=200; ZEPS: Real=1.0e-12)
---Purpose:
-- Given the starting point StartingPoint,
-- the Broyden-Fletcher-Goldfarb-Shanno variant of Davidson-Fletcher-Powell
-- minimization is done on the function F.
-- The tolerance required on F is given by Tolerance.
-- The solution F = Fi is found when :
-- 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1) + ZEPS).
-- The maximum number of iterations allowed is given by NbIterations.
returns BFGS;
Create(F: in out MultipleVarFunctionWithGradient;
Tolerance: Real = 1.0e-8;
NbIterations: Integer = 200;
ZEPS: Real = 1.0e-12)
---Purpose: Initializes the computation of the minimum of F.
-- Warning
-- A call to the Perform method must be made after this
-- initialization to effectively compute the minimum of the
-- function F.
returns BFGS;
Delete(me:out) is virtual;
---C++: alias "Standard_EXPORT virtual ~math_BFGS(){Delete() ; }"
Perform(me: in out; F: in out MultipleVarFunctionWithGradient;
StartingPoint: Vector)
---Purpose: Is used internally by the constructors.
is static;
IsSolutionReached(me; F: in out MultipleVarFunctionWithGradient)
---Purpose:
-- This method is called at the end of each iteration to check if the
-- solution is found.
-- It can be redefined in a sub-class to implement a specific test to
-- stop the iterations.
returns Boolean
is virtual;
IsDone(me)
---Purpose: Returns true if the computations are successful, otherwise returns false.
---C++: inline
returns Boolean
is static;
Location(me)
---Purpose: returns the location vector of the minimum.
-- Exception NotDone is raised if the minimum was not found.
---C++: inline
---C++: return const&
returns Vector
raises NotDone
is static;
Location(me; Loc: out Vector)
---Purpose: outputs the location vector of the minimum in Loc.
-- Exception NotDone is raised if the minimum was not found.
-- Exception DimensionError is raised if the range of Loc is not
-- equal to the range of the StartingPoint.
---C++: inline
raises DimensionError,
NotDone
is static;
Minimum(me)
---Purpose: returns the value of the minimum.
-- Exception NotDone is raised if the minimum was not found.
---C++: inline
returns Real
raises NotDone
is static;
Gradient(me)
---Purpose: Returns the gradient vector at the minimum.
-- Exception NotDone is raised if the minimum was not found.
---C++: inline
---C++: return const&
returns Vector
raises NotDone
is static;
Gradient(me; Grad: out Vector)
---Purpose: Returns the value of the gradient vector at the minimum in Grad.
-- Exception NotDone is raised if the minimum was not found.
-- Exception DimensionError is raised if the range of Grad is not
-- equal to the range of the StartingPoint.
---C++: inline
raises DimensionError,
NotDone
is static;
NbIterations(me)
---Purpose: Returns the number of iterations really done in the
-- calculation of the minimum.
-- The exception NotDone is raised if the minimum was not found.
---C++: inline
returns Integer
raises NotDone
is static;
Dump(me; o: in out OStream)
---Purpose: Prints on the stream o information on the current state
-- of the object.
-- Is used to redefine the operator <<.
is static;
fields
Done: Boolean;
TheStatus: Status is protected;
TheLocation: Vector is protected;
TheGradient: Vector is protected;
PreviousMinimum: Real is protected;
TheMinimum: Real is protected;
XTol: Real is protected;
EPSZ: Real is protected;
nbiter: Integer is protected;
Itermax: Integer;
end BFGS;

308
src/math/math_BFGS.cxx Executable file
View File

@@ -0,0 +1,308 @@
//static const char* sccsid = "@(#)math_BFGS.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
//#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#define No_Standard_DimensionError
//#endif
#include <math_BFGS.ixx>
#include <math_BracketMinimum.hxx>
#include <math_BrentMinimum.hxx>
#include <math_FunctionWithDerivative.hxx>
#include <math_MultipleVarFunctionWithGradient.hxx>
#include <math_Matrix.hxx>
#define R 0.61803399
#define C (1.0-R)
#define SHFT(a,b,c,d) (a)=(b);(b)=(c);(c)=(d);
#define SIGN(a, b) ((b) > 0.0 ? fabs(a) : -fabs(a))
#define MOV3(a,b,c, d, e, f) (a)=(d); (b)= (e); (c)=(f);
// l'utilisation de math_BrentMinumim pur trouver un minimum dans une direction
// donnee n'est pas du tout optimale. voir peut etre interpolation cubique
// classique et aussi essayer "recherche unidimensionnelle economique"
// PROGRAMMATION MATHEMATIQUE (theorie et algorithmes) tome1 page 82.
class DirFunction : public math_FunctionWithDerivative {
math_Vector *P0;
math_Vector *Dir;
math_Vector *P;
math_Vector *G;
math_MultipleVarFunctionWithGradient *F;
public :
DirFunction(math_Vector& V1,
math_Vector& V2,
math_Vector& V3,
math_Vector& V4,
math_MultipleVarFunctionWithGradient& f) ;
void Initialize(const math_Vector& p0, const math_Vector& dir) const;
void TheGradient(math_Vector& Grad);
virtual Standard_Boolean Value(const Standard_Real x, Standard_Real& fval) ;
virtual Standard_Boolean Values(const Standard_Real x, Standard_Real& fval, Standard_Real& D) ;
virtual Standard_Boolean Derivative(const Standard_Real x, Standard_Real& D) ;
};
DirFunction::DirFunction(math_Vector& V1,
math_Vector& V2,
math_Vector& V3,
math_Vector& V4,
math_MultipleVarFunctionWithGradient& f) {
P0 = &V1;
Dir = &V2;
P = &V3;
F = &f;
G = &V4;
}
void DirFunction::Initialize(const math_Vector& p0,
const math_Vector& dir) const{
*P0 = p0;
*Dir = dir;
}
void DirFunction::TheGradient(math_Vector& Grad) {
Grad = *G;
}
Standard_Boolean DirFunction::Value(const Standard_Real x,
Standard_Real& fval)
{
*P = *Dir;
P->Multiply(x);
P->Add(*P0);
F->Value(*P, fval);
return Standard_True;
}
Standard_Boolean DirFunction::Values(const Standard_Real x,
Standard_Real& fval,
Standard_Real& D)
{
*P = *Dir;
P->Multiply(x);
P->Add(*P0);
F->Values(*P, fval, *G);
D = (*G).Multiplied(*Dir);
return Standard_True;
}
Standard_Boolean DirFunction::Derivative(const Standard_Real x,
Standard_Real& D)
{
*P = *Dir;
P->Multiply(x);
P->Add(*P0);
Standard_Real fval;
F->Values(*P, fval, *G);
D = (*G).Multiplied(*Dir);
return Standard_True;
}
static Standard_Boolean MinimizeDirection(math_Vector& P,
Standard_Real F0,
math_Vector& Gr,
math_Vector& Dir,
Standard_Real& Result,
DirFunction& F) {
Standard_Real ax, xx, bx, Fax, Fxx, Fbx, F1;
F.Initialize(P, Dir);
Standard_Real dy1, Hnr1, lambda, alfa=0;
#ifdef DEB
Standard_Integer n =
#endif
Dir.Length();
dy1 = Gr*Dir;
if (dy1 != 0) {
Hnr1 = Dir.Norm2();
alfa = 0.7*(-F0)/dy1;
lambda = 0.015/Sqrt(Hnr1);
}
else lambda = 1.0;
if (lambda > alfa) lambda = alfa;
F.Value(lambda, F1);
math_BracketMinimum Bracket(F, 0.0, lambda, F0, F1);
if(Bracket.IsDone()) {
Bracket.Values(ax, xx, bx);
Bracket.FunctionValues(Fax, Fxx, Fbx);
Standard_Integer niter = 100;
Standard_Real tol = 1.e-03;
math_BrentMinimum Sol(tol, Fxx, niter, 1.e-08);
Sol.Perform(F, ax, xx, bx);
if(Sol.IsDone()) {
Standard_Real Scale = Sol.Location();
Result = Sol.Minimum();
Dir.Multiply(Scale);
P.Add(Dir);
return Standard_True;
}
}
return Standard_False;
}
void math_BFGS::Perform(math_MultipleVarFunctionWithGradient& F,
const math_Vector& StartingPoint) {
Standard_Boolean Good;
Standard_Integer n = TheLocation.Length();
Standard_Integer j, i;
Standard_Real fae, fad, fac;
math_Vector xi(1, n), dg(1, n), hdg(1, n);
math_Matrix hessin(1, n, 1, n);
hessin.Init(0.0);
math_Vector Temp1(1, n);
math_Vector Temp2(1, n);
math_Vector Temp3(1, n);
math_Vector Temp4(1, n);
DirFunction F_Dir(Temp1, Temp2, Temp3, Temp4, F);
TheLocation = StartingPoint;
Good = F.Values(TheLocation, PreviousMinimum, TheGradient);
if(!Good) {
Done = Standard_False;
TheStatus = math_FunctionError;
return;
}
for(i = 1; i <= n; i++) {
hessin(i, i) = 1.0;
xi(i) = -TheGradient(i);
}
for(nbiter = 1; nbiter <= Itermax; nbiter++) {
TheMinimum = PreviousMinimum;
Standard_Boolean IsGood = MinimizeDirection(TheLocation, TheMinimum,
TheGradient,
xi, TheMinimum, F_Dir);
if(!IsGood) {
Done = Standard_False;
TheStatus = math_DirectionSearchError;
return;
}
if(IsSolutionReached(F)) {
Done = Standard_True;
TheStatus = math_OK;
return;
}
if (nbiter == Itermax) {
Done = Standard_False;
TheStatus = math_TooManyIterations;
return;
}
PreviousMinimum = TheMinimum;
dg = TheGradient;
Good = F.Values(TheLocation, TheMinimum, TheGradient);
if(!Good) {
Done = Standard_False;
TheStatus = math_FunctionError;
return;
}
for(i = 1; i <= n; i++) {
dg(i) = TheGradient(i) - dg(i);
}
for(i = 1; i <= n; i++) {
hdg(i) = 0.0;
for (j = 1; j <= n; j++)
hdg(i) += hessin(i, j) * dg(j);
}
fac = fae = 0.0;
for(i = 1; i <= n; i++) {
fac += dg(i) * xi(i);
fae += dg(i) * hdg(i);
}
fac = 1.0 / fac;
fad = 1.0 / fae;
for(i = 1; i <= n; i++)
dg(i) = fac * xi(i) - fad * hdg(i);
for(i = 1; i <= n; i++)
for(j = 1; j <= n; j++)
hessin(i, j) += fac * xi(i) * xi(j)
- fad * hdg(i) * hdg(j) + fae * dg(i) * dg(j);
for(i = 1; i <= n; i++) {
xi(i) = 0.0;
for (j = 1; j <= n; j++) xi(i) -= hessin(i, j) * TheGradient(j);
}
}
Done = Standard_False;
TheStatus = math_TooManyIterations;
return;
}
Standard_Boolean math_BFGS::IsSolutionReached(
math_MultipleVarFunctionWithGradient&) const {
return 2.0 * fabs(TheMinimum - PreviousMinimum) <=
XTol * (fabs(TheMinimum) + fabs(PreviousMinimum) + EPSZ);
}
math_BFGS::math_BFGS(math_MultipleVarFunctionWithGradient& F,
const math_Vector& StartingPoint,
const Standard_Real Tolerance,
const Standard_Integer NbIterations,
const Standard_Real ZEPS)
: TheLocation(1, StartingPoint.Length()),
TheGradient(1, StartingPoint.Length()) {
XTol = Tolerance;
EPSZ = ZEPS;
Itermax = NbIterations;
Perform(F, StartingPoint);
}
math_BFGS::math_BFGS(math_MultipleVarFunctionWithGradient& F,
const Standard_Real Tolerance,
const Standard_Integer NbIterations,
const Standard_Real ZEPS)
: TheLocation(1, F.NbVariables()),
TheGradient(1, F.NbVariables()) {
XTol = Tolerance;
EPSZ = ZEPS;
Itermax = NbIterations;
}
void math_BFGS::Delete()
{}
void math_BFGS::Dump(Standard_OStream& o) const {
o<< "math_BFGS resolution: ";
if(Done) {
o << " Status = Done \n";
o <<" Location Vector = " << Location() << "\n";
o <<" Minimum value = "<< Minimum()<<"\n";
o <<" Number of iterations = "<<NbIterations() <<"\n";;
}
else {
o<< " Status = not Done because " << (Standard_Integer)TheStatus << "\n";
}
}

49
src/math/math_BFGS.lxx Executable file
View File

@@ -0,0 +1,49 @@
// file math_BFGS.lxx
#include <StdFail_NotDone.hxx>
#include <math_Vector.hxx>
inline Standard_Boolean math_BFGS::IsDone() const { return Done; }
inline Standard_OStream& operator<<(Standard_OStream& o,
const math_BFGS& B)
{
B.Dump(o);
return o;
}
inline const math_Vector& math_BFGS::Location() const{
StdFail_NotDone_Raise_if(!Done, " ");
return TheLocation;
}
inline void math_BFGS::Location(math_Vector& Loc) const{
StdFail_NotDone_Raise_if(!Done, " ");
Loc = TheLocation;
}
inline Standard_Real math_BFGS::Minimum() const{
StdFail_NotDone_Raise_if(!Done, " ");
return TheMinimum;
}
inline const math_Vector& math_BFGS::Gradient() const {
StdFail_NotDone_Raise_if(!Done, " ");
return TheGradient;
}
inline void math_BFGS::Gradient(math_Vector& Grad) const {
StdFail_NotDone_Raise_if(!Done, " ");
Grad = TheGradient;
}
inline Standard_Integer math_BFGS::NbIterations() const {
StdFail_NotDone_Raise_if(!Done, " ");
return nbiter;
}

111
src/math/math_BissecNewton.cdl Executable file
View File

@@ -0,0 +1,111 @@
-- File: BissecNewton.cdl
-- Created: Tue 14 10:42:34 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class BissecNewton from math
---Purpose:
-- This class implements a combination of Newton-Raphson and bissection
-- methods to find the root of the function between two bounds.
-- Knowledge of the derivative is required.
uses Vector from math,
Matrix from math,
FunctionWithDerivative from math,
Status from math,
OStream from Standard
raises NotDone from StdFail
is
Perform(me: in out; F: out FunctionWithDerivative;
Bound1, Bound2: Real;
NbIterations: Integer)
is static protected;
Create(F: in out FunctionWithDerivative;
Bound1, Bound2, TolX: Real;
NbIterations: Integer = 100)
---Purpose:
-- A combination of Newton-Raphson and bissection methods is done to find
-- the root of the function F between the bounds Bound1 and Bound2.
-- on the function F.
-- The tolerance required on the root is given by TolX.
-- The solution is found when :
-- abs(Xi - Xi-1) <= TolX and F(Xi) * F(Xi-1) <= 0
-- The maximum number of iterations allowed is given by NbIterations.
returns BissecNewton;
IsSolutionReached(me: in out; F: out FunctionWithDerivative)
---Purpose:
-- This method is called at the end of each iteration to check if the
-- solution has been found.
-- It can be redefined in a sub-class to implement a specific test to
-- stop the iterations.
returns Boolean
is virtual;
IsDone(me)
---Purpose: Tests is the root has been successfully found.
---C++: inline
returns Boolean
is static;
Root(me)
---Purpose: returns the value of the root.
-- Exception NotDone is raised if the minimum was not found.
---C++: inline
returns Real
raises NotDone
is static;
Derivative(me)
---Purpose: returns the value of the derivative at the root.
-- Exception NotDone is raised if the minimum was not found.
---C++: inline
returns Real
raises NotDone
is static;
Value(me)
---Purpose: returns the value of the function at the root.
-- Exception NotDone is raised if the minimum was not found.
---C++: inline
returns Real
raises NotDone
is static;
Dump(me; o: in out OStream)
---Purpose: Prints on the stream o information on the current state
-- of the object.
-- Is used to redifine the operator <<.
is static;
fields
Done: Boolean;
TheStatus: Status is protected;
XTol: Real is protected;
x: Real is protected;
dx: Real is protected;
f: Real is protected;
df: Real is protected;
end BissecNewton;

143
src/math/math_BissecNewton.cxx Executable file
View File

@@ -0,0 +1,143 @@
//static const char* sccsid = "@(#)math_BissecNewton.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
#include <math_BissecNewton.ixx>
#include <math_FunctionWithDerivative.hxx>
void math_BissecNewton::Perform(math_FunctionWithDerivative& F,
const Standard_Real Bound1,
const Standard_Real Bound2,
const Standard_Integer NbIterations)
{
Standard_Boolean GOOD;
Standard_Integer j;
Standard_Real dxold, fh, fl;
Standard_Real swap, temp, xh, xl;
GOOD = F.Values(Bound1, fl, df);
if(!GOOD) {
Done = Standard_False;
TheStatus = math_FunctionError;
return;
}
GOOD = F.Values(Bound2, fh, df);
if(!GOOD) {
Done = Standard_False;
TheStatus = math_FunctionError;
return;
}
// Modified by Sergey KHROMOV - Wed Jan 22 12:06:45 2003 Begin
Standard_Real aFTol = RealEpsilon();
// if(fl * fh >= 0.0) {
if(fl * fh > aFTol*aFTol) {
Done = Standard_False;
TheStatus = math_NotBracketed;
return;
}
// if(fl < 0.0) {
if(fl < -aFTol || (fl < aFTol && fh < -aFTol)) {
xl = Bound1;
xh = Bound2;
}
else {
xl = Bound2;
xh = Bound1;
swap = fl;
fl = fh;
fh = swap;
}
// Modified by Sergey KHROMOV - Wed Jan 22 12:06:49 2003 End
x = 0.5 * (Bound1 + Bound2);
dxold = fabs(Bound2 - Bound1);
dx = dxold;
GOOD = F.Values(x, f, df);
if(!GOOD) {
Done = Standard_False;
TheStatus = math_FunctionError;
return;
}
for(j = 1; j <= NbIterations; j++) {
if((((x - xh) * df - f) * ((x - xl) * df - f) >= 0.0)
|| (fabs(2.0 * f) > fabs(dxold * df))) {
dxold = dx;
dx = 0.5 * (xh - xl);
x = xl + dx;
if(xl == x) {
TheStatus = math_OK;
Done = Standard_True;
return;
}
}
else {
dxold = dx;
dx = f / df;
temp = x;
x -= dx;
if(temp == x) {
TheStatus = math_OK;
Done = Standard_True;
return;
}
}
if(IsSolutionReached(F)) {
TheStatus = math_OK;
Done = Standard_True;
return;
}
GOOD = F.Values(x, f, df);
if(!GOOD) {
Done = Standard_False;
TheStatus = math_FunctionError;
return;
}
if(f < 0.0) {
xl = x;
fl = f;
}
else if(f > 0.0) {
xh = x;
fh = f;
}
else {
TheStatus = math_OK;
Done = Standard_True;
return;
}
}
TheStatus = math_TooManyIterations;
Done = Standard_False;
return;
}
Standard_Boolean math_BissecNewton::IsSolutionReached
//(math_FunctionWithDerivative& F)
(math_FunctionWithDerivative& )
{
return Abs(dx) <= XTol;
}
math_BissecNewton::math_BissecNewton(math_FunctionWithDerivative& F,
const Standard_Real Bound1,
const Standard_Real Bound2,
const Standard_Real TolX,
const Standard_Integer NbIterations) {
XTol = TolX;
Perform(F, Bound1, Bound2, NbIterations);
}
void math_BissecNewton::Dump(Standard_OStream& o) const {
o << "math_BissecNewton ";
if(Done) {
o << " Status = Done \n";
o << " The Root is: " << x << endl;
o << " The value at this Root is: " << f << endl;
}
else {
o << " Status = not Done \n";
}
}

35
src/math/math_BissecNewton.lxx Executable file
View File

@@ -0,0 +1,35 @@
// File math_BissecNewton.lxx
#include <StdFail_NotDone.hxx>
inline Standard_OStream& operator<<(Standard_OStream& o,
const math_BissecNewton& Bi)
{
Bi.Dump(o);
return o;
}
inline Standard_Boolean math_BissecNewton::IsDone() const { return Done; }
inline Standard_Real math_BissecNewton::Root() const{
StdFail_NotDone_Raise_if(!Done, " ");
return x;
}
inline Standard_Real math_BissecNewton::Derivative() const{
StdFail_NotDone_Raise_if(!Done, " ");
return df;
}
inline Standard_Real math_BissecNewton::Value() const{
StdFail_NotDone_Raise_if(!Done, " ");
return f;
}

110
src/math/math_BracketMinimum.cdl Executable file
View File

@@ -0,0 +1,110 @@
-- File: BracketMinimum.cdl
-- Created: Tue May 14 14:55:21 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class BracketMinimum from math
---Purpose:Given two distinct initial points, BracketMinimum
-- implements the computation of three points (a, b, c) which
-- bracket the minimum of the function and verify A less than
-- B, B less than C and F(A) less than F(B), F(B) less than (C).
uses Vector from math,
Matrix from math,
Function from math,
OStream from Standard
raises NotDone from StdFail
is
Create(F: in out Function; A, B: Real)
---Purpose:
-- Given two initial values this class computes a
-- bracketing triplet of abscissae Ax, Bx, Cx
-- (such that Bx is between Ax and Cx, F(Bx) is
-- less than both F(Bx) and F(Cx)) the Brent minimization is done
-- on the function F.
returns BracketMinimum;
Create(F: in out Function; A, B, FA: Real)
---Purpose:
-- Given two initial values this class computes a
-- bracketing triplet of abscissae Ax, Bx, Cx
-- (such that Bx is between Ax and Cx, F(Bx) is
-- less than both F(Bx) and F(Cx)) the Brent minimization is done
-- on the function F.
-- This constructor has to be used if F(A) is known.
returns BracketMinimum;
Create(F: in out Function; A, B, FA, FB: Real)
---Purpose:
-- Given two initial values this class computes a
-- bracketing triplet of abscissae Ax, Bx, Cx
-- (such that Bx is between Ax and Cx, F(Bx) is
-- less than both F(Bx) and F(Cx)) the Brent minimization is done
-- on the function F.
-- This constructor has to be used if F(A) and F(B) are known.
returns BracketMinimum;
Perform(me: in out; F: in out Function; A, B: Real)
---Purpose: Is used internally by the constructors.
is static protected;
IsDone(me)
---Purpose: Returns true if the computations are successful, otherwise returns false.
---C++: inline
returns Boolean
is static;
Values(me; A, B, C: out Real)
---Purpose: Returns the bracketed triplet of abscissae.
-- Exceptions
-- StdFail_NotDone if the algorithm fails (and IsDone returns false).
raises NotDone
is static;
FunctionValues(me; FA, FB, FC: out Real)
---Purpose: returns the bracketed triplet function values.
-- Exceptions
-- StdFail_NotDone if the algorithm fails (and IsDone returns false).
raises NotDone
is static;
Dump(me; o: in out OStream)
---Purpose: Prints on the stream o information on the current state
-- of the object.
-- Is used to redefine the operator <<.
is static;
fields
Done: Boolean;
Ax: Real;
Bx: Real;
Cx: Real;
FAx: Real;
FBx: Real;
FCx: Real;
myFA: Boolean;
myFB: Boolean;
end BracketMinimum;

163
src/math/math_BracketMinimum.cxx Executable file
View File

@@ -0,0 +1,163 @@
//static const char* sccsid = "@(#)math_BracketMinimum.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
#include <math_BracketMinimum.ixx>
#include <StdFail_NotDone.hxx> // waiting for NotDone Exception
#include <math_Function.hxx>
#define GOLD 1.618034
#define CGOLD 0.3819660
#define GLIMIT 100.0
#define TINY 1.0e-20
#ifdef MAX
#undef MAX
#endif
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define SIGN(a,b) ((b) > 0.0 ? fabs(a) : -fabs(a))
#define SHFT(a,b,c,d) (a)=(b);(b)=(c);(c)=(d)
void math_BracketMinimum::Perform(math_Function& F,
const Standard_Real A,
const Standard_Real B) {
Standard_Boolean OK;
Standard_Real ulim, u, r, q, f, fu, dum;
Done = Standard_False;
Ax = A;
Bx = B;
Standard_Real Lambda = GOLD;
if (!myFA) {
OK = F.Value(Ax, FAx);
if(!OK) return;
}
if (!myFB) {
OK = F.Value(Bx, FBx);
if(!OK) return;
}
if(FBx > FAx) {
SHFT(dum, Ax, Bx, dum);
SHFT(dum, FBx, FAx, dum);
}
Cx = Bx + Lambda * (Bx - Ax);
OK = F.Value(Cx, FCx);
if(!OK) return;
while(FBx > FCx) {
r = (Bx - Ax) * (FBx -FCx);
q = (Bx - Cx) * (FBx -FAx);
u = Bx - ((Bx - Cx) * q - (Bx - Ax) * r) /
(2.0 * SIGN(MAX(fabs(q - r), TINY), q - r));
ulim = Bx + GLIMIT * (Cx - Bx);
if((Bx - u) * (u - Cx) > 0.0) {
OK = F.Value(u, fu);
if(!OK) return;
if(fu < FCx) {
Ax = Bx;
Bx = u;
FAx = FBx;
FBx = fu;
Done = Standard_True;
return;
}
else if(fu > FBx) {
Cx = u;
FCx = fu;
Done = Standard_True;
return;
}
u = Cx + Lambda * (Cx - Bx);
OK = F.Value(u, fu);
if(!OK) return;
}
else if((Cx - u) * (u - ulim) > 0.0) {
OK = F.Value(u, fu);
if(!OK) return;
if(fu < FCx) {
SHFT(Bx, Cx, u, Cx + GOLD * (Cx - Bx));
OK = F.Value(u, f);
if(!OK) return;
SHFT(FBx, FCx, fu, f);
}
}
else if ((u - ulim) * (ulim - Cx) >= 0.0) {
u = ulim;
OK = F.Value(u, fu);
if(!OK) return;
}
else {
u = Cx + GOLD * (Cx - Bx);
OK = F.Value(u, fu);
if(!OK) return;
}
SHFT(Ax, Bx, Cx, u);
SHFT(FAx, FBx, FCx, fu);
}
Done = Standard_True;
}
math_BracketMinimum::math_BracketMinimum(math_Function& F,
const Standard_Real A,
const Standard_Real B) {
myFA = Standard_False;
myFB = Standard_False;
Perform(F, A, B);
}
math_BracketMinimum::math_BracketMinimum(math_Function& F,
const Standard_Real A,
const Standard_Real B,
const Standard_Real FA) {
FAx = FA;
myFA = Standard_True;
myFB = Standard_False;
Perform(F, A, B);
}
math_BracketMinimum::math_BracketMinimum(math_Function& F,
const Standard_Real A,
const Standard_Real B,
const Standard_Real FA,
const Standard_Real FB) {
FAx = FA;
FBx = FB;
myFA = Standard_True;
myFB = Standard_True;
Perform(F, A, B);
}
void math_BracketMinimum::Values(Standard_Real& A, Standard_Real& B, Standard_Real& C) const{
StdFail_NotDone_Raise_if(!Done, " ");
A = Ax;
B = Bx;
C = Cx;
}
void math_BracketMinimum::FunctionValues(Standard_Real& FA, Standard_Real& FB, Standard_Real& FC) const{
StdFail_NotDone_Raise_if(!Done, " ");
FA = FAx;
FB = FBx;
FC = FCx;
}
void math_BracketMinimum::Dump(Standard_OStream& o) const {
o << "math_BracketMinimum ";
if(Done) {
o << " Status = Done \n";
o << " The bracketed triplet is: " << endl;
o << Ax << ", " << Bx << ", " << Cx << endl;
o << " The corresponding function values are: "<< endl;
o << FAx << ", " << FBx << ", " << FCx << endl;
}
else {
o << " Status = not Done \n";
}
}

View File

@@ -0,0 +1,10 @@
// math_BracketMinimum.lxx
inline Standard_Boolean math_BracketMinimum::IsDone() const { return Done; }
inline Standard_OStream& operator<<(Standard_OStream& o,
const math_BracketMinimum& Br)
{
Br.Dump(o);
return o;
}

87
src/math/math_BracketedRoot.cdl Executable file
View File

@@ -0,0 +1,87 @@
-- File: BracketedRoot.cdl
-- Created: Tue May 14 14:10:21 1991
-- Author: Laurent Painnot
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class BracketedRoot from math
---Purpose: This class implements the Brent method to find the root of a function
-- located within two bounds. No knowledge of the derivative is required.
uses Matrix from math,
Vector from math,
Function from math,
OStream from Standard
raises NotDone
is
Create(F: in out Function;
Bound1, Bound2, Tolerance: Real;
NbIterations: Integer = 100; ZEPS : Real =1.0e-12)
---Purpose:
-- The Brent method is used to find the root of the function F between
-- the bounds Bound1 and Bound2 on the function F.
-- If F(Bound1)*F(Bound2) >0 the Brent method fails.
-- The tolerance required for the root is given by Tolerance.
-- The solution is found when :
-- abs(Xi - Xi-1) <= Tolerance;
-- The maximum number of iterations allowed is given by NbIterations.
returns BracketedRoot;
IsDone(me)
---Purpose: Returns true if the computations are successful, otherwise returns false.
---C++: inline
returns Boolean
is static;
Root(me)
---Purpose: returns the value of the root.
-- Exception NotDone is raised if the minimum was not found.
---C++: inline
returns Real
raises NotDone
is static;
Value(me)
---Purpose: returns the value of the function at the root.
-- Exception NotDone is raised if the minimum was not found.
---C++: inline
returns Real
raises NotDone
is static;
NbIterations(me)
---Purpose: returns the number of iterations really done during the
-- computation of the Root.
-- Exception NotDone is raised if the minimum was not found.
---C++: inline
returns Integer
raises NotDone
is static;
Dump(me; o: in out OStream)
---Purpose: Prints on the stream o information on the current state
-- of the object.
is static;
fields
Done: Boolean;
TheRoot: Real;
TheError: Real;
NbIter: Integer;
end BracketedRoot;

104
src/math/math_BracketedRoot.cxx Executable file
View File

@@ -0,0 +1,104 @@
//static const char* sccsid = "@(#)math_BracketedRoot.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
#include <math_BracketedRoot.ixx>
#include <math_Function.hxx>
// reference algorithme:
// Brent method
// numerical recipes in C p 269
math_BracketedRoot::math_BracketedRoot (math_Function& F,
const Standard_Real Bound1,
const Standard_Real Bound2,
const Standard_Real Tolerance,
const Standard_Integer NbIterations,
const Standard_Real ZEPS ) {
Standard_Real Fa,Fc,a,c=0,d=0,e=0;
Standard_Real min1,min2,p,q,r,s,tol1,xm;
Standard_Boolean Ok;
a = Bound1;
TheRoot = Bound2;
Ok = F.Value(a,Fa);
Ok = F.Value(TheRoot,TheError);
if (Fa*TheError > 0.) { Done = Standard_False;}
else {
Fc = TheError ;
for (NbIter = 1; NbIter <= NbIterations; NbIter++) {
if (TheError*Fc > 0.) {
c = a; // rename a TheRoot c and adjust bounding interval d
Fc = Fa;
d = TheRoot - a;
e = d;
}
if ( Abs(Fc) < Abs(Fa) ) {
a = TheRoot;
TheRoot = c;
c = a;
Fa = TheError;
TheError = Fc;
Fc = Fa;
}
tol1 = 2.*ZEPS * Abs(TheRoot) + 0.5 * Tolerance; // convergence check
xm = 0.5 * ( c - TheRoot );
if (Abs(xm) <= tol1 || TheError == 0. ) {
Done = Standard_True;
return;
}
if (Abs(e) >= tol1 && Abs(Fa) > Abs(TheError) ) {
s = TheError / Fa; // attempt inverse quadratic interpolation
if (a == c) {
p = 2.*xm*s;
q = 1. - s;
}
else {
q = Fa / Fc;
r = TheError / Fc;
p = s * (2.*xm *q * (q - r) - (TheRoot - a)*(r - 1.));
q = (q -1.) * (r - 1.) * (s - 1.);
}
if ( p > 0. ) { q = -q;} // check whether in bounds
p = Abs(p);
min1 = 3.* xm* q - Abs(tol1 *q);
min2 = Abs(e * q);
if (2.* p < (min1 < min2 ? min1 : min2) ) {
e = d ; // accept interpolation
d = p / q;
}
else {
d = xm; // interpolation failed,use bissection
e = d;
}
}
else { // bounds decreasing too slowly ,use bissection
d = xm;
e =d;
}
a = TheRoot ; // move last best guess to a
Fa = TheError;
if (Abs(d) > tol1) { // evaluate new trial root
TheRoot += d;
}
else {
TheRoot += (xm > 0. ? Abs(tol1) : -Abs(tol1));
}
Ok = F.Value(TheRoot,TheError);
}
Done = Standard_False;
}
}
void math_BracketedRoot::Dump(Standard_OStream& o) const {
o << "math_BracketedRoot ";
if(Done) {
o << " Status = Done \n";
o << " Number of iterations = " << NbIter << endl;
o << " The Root is: " << TheRoot << endl;
o << " The value at the root is: " << TheError << endl;
}
else {
o << " Status = not Done \n";
}
}

32
src/math/math_BracketedRoot.lxx Executable file
View File

@@ -0,0 +1,32 @@
// file math_BracketedRoot.lxx
#include <StdFail_NotDone.hxx>
inline Standard_Boolean math_BracketedRoot::IsDone() const { return Done; }
inline Standard_OStream& operator<<(Standard_OStream& o,
const math_BracketedRoot& Br)
{
Br.Dump(o);
return o;
}
inline Standard_Real math_BracketedRoot::Root () const {
StdFail_NotDone_Raise_if(!Done, " ");
return TheRoot;
}
inline Standard_Real math_BracketedRoot::Value () const {
StdFail_NotDone_Raise_if(!Done, " ");
return TheError;
}
inline Standard_Integer math_BracketedRoot::NbIterations ()const {
StdFail_NotDone_Raise_if(!Done, " ");
return NbIter;
}

146
src/math/math_BrentMinimum.cdl Executable file
View File

@@ -0,0 +1,146 @@
-- File: BrentMinimum.cdl
-- Created: Tue May 14 16:20:21 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class BrentMinimum from math
---Purpose:
-- This class implements the Brent's method to find the minimum of
-- a function of a single variable.
-- No knowledge of the derivative is required.
uses Matrix from math,
Vector from math,
Function from math,
OStream from Standard
raises NotDone from StdFail
is
Create(TolX: Real;
NbIterations: Integer = 100;
ZEPS: Real = 1.0e-12)
---Purpose:
-- This constructor should be used in a sub-class to initialize
-- correctly all the fields of this class.
returns BrentMinimum;
Create(TolX: Real; Fbx: Real;
NbIterations: Integer = 100;
ZEPS: Real = 1.0e-12)
---Purpose:
-- This constructor should be used in a sub-class to initialize
-- correctly all the fields of this class.
-- It has to be used if F(Bx) is known.
returns BrentMinimum;
Create(F: in out Function; Ax, Bx, Cx, TolX: Real;
NbIterations: Integer = 100; ZEPS: Real=1.0e-12)
---Purpose:
-- Given a bracketing triplet of abscissae Ax, Bx, Cx
-- (such as Bx is between Ax and Cx, F(Bx) is
-- less than both F(Bx) and F(Cx)) the Brent minimization is done
-- on the function F.
-- The tolerance required on F is given by Tolerance.
-- The solution is found when :
-- abs(Xi - Xi-1) <= TolX * abs(Xi) + ZEPS;
-- The maximum number of iterations allowed is given by NbIterations.
returns BrentMinimum;
Perform(me: in out; F: in out Function;
Ax, Bx, Cx: Real)
---Purpose:
-- Brent minimization is performed on function F from a given
-- bracketing triplet of abscissas Ax, Bx, Cx (such that Bx is
-- between Ax and Cx, F(Bx) is less than both F(Bx) and F(Cx))
-- Warning
-- The initialization constructors must have been called
-- before the call to the Perform method.
is static;
IsSolutionReached(me: in out; F: in out Function)
---Purpose:
-- This method is called at the end of each iteration to check if the
-- solution is found.
-- It can be redefined in a sub-class to implement a specific test to
-- stop the iterations.
returns Boolean
is virtual;
IsDone(me)
---Purpose: Returns true if the computations are successful, otherwise returns false.
---C++: inline
returns Boolean
is static;
Location(me)
---Purpose: returns the location value of the minimum.
-- Exception NotDone is raised if the minimum was not found.
---C++: inline
returns Real
raises NotDone
is static;
Minimum(me)
---Purpose: returns the value of the minimum.
-- Exception NotDone is raised if the minimum was not found.
---C++: inline
returns Real
raises NotDone
is static;
NbIterations(me)
---Purpose: returns the number of iterations really done during the
-- computation of the minimum.
-- Exception NotDone is raised if the minimum was not found.
---C++: inline
returns Integer
raises NotDone
is static;
Dump(me; o: in out OStream)
---Purpose: Prints on the stream o information on the current state
-- of the object.
-- Is used to redefine the operator <<.
is static;
fields
Done: Boolean;
a: Real is protected;
b: Real is protected;
x: Real is protected;
fx: Real is protected;
fv: Real is protected;
fw: Real is protected;
iter: Integer;
XTol: Real is protected;
EPSZ: Real is protected;
Itermax: Integer;
myF: Boolean;
end BrentMinimum;

156
src/math/math_BrentMinimum.cxx Executable file
View File

@@ -0,0 +1,156 @@
//static const char* sccsid = "@(#)math_BrentMinimum.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
#include <math_BrentMinimum.ixx>
#include <math_Function.hxx>
#define CGOLD 0.3819660
#ifdef MAX
#undef MAX
#endif
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define SIGN(a,b) ((b) > 0.0 ? fabs(a) : -fabs(a))
#define SHFT(a,b,c,d) (a)=(b);(b)=(c);(c)=(d)
void math_BrentMinimum::Perform(math_Function& F,
const Standard_Real ax,
const Standard_Real bx,
const Standard_Real cx) {
Standard_Boolean OK;
Standard_Real etemp, fu, p, q, r;
Standard_Real tol1, tol2, u, v, w, xm;
Standard_Real e = 0.0;
Standard_Real d = RealLast();
a = ((ax < cx) ? ax : cx);
b = ((ax > cx) ? ax : cx);
x = w = v = bx;
if (!myF) {
OK = F.Value(x, fx);
if(!OK) return;
}
fw = fv = fx;
for(iter = 1; iter <= Itermax; iter++) {
xm = 0.5 * (a + b);
tol1 = XTol * fabs(x) + EPSZ;
tol2 = 2.0 * tol1;
if(IsSolutionReached(F)) {
Done = Standard_True;
return;
}
if(fabs(e) > tol1) {
r = (x - w) * (fx - fv);
q = (x - v) * (fx - fw);
p = (x - v) * q - (x - w) * r;
q = 2.0 * (q - r);
if(q > 0.0) p = -p;
q = fabs(q);
etemp = e;
e = d;
if(fabs(p) >= fabs(0.5 * q * etemp)
|| p <= q * ( a - x) || p >= q * (b - x)) {
e = (x >= xm ? a - x : b - x);
d = CGOLD * e;
}
else {
d = p / q;
u = x + d;
if(u - a < tol2 || b - u < tol2) d = SIGN(tol1, xm - x);
}
}
else {
e = (x >= xm ? a - x : b - x);
d = CGOLD * e;
}
u = (fabs(d) >= tol1 ? x + d : x + SIGN(tol1, d));
OK = F.Value(u, fu);
if(!OK) return;
if(fu <= fx) {
if(u >= x) a = x; else b = x;
SHFT(v, w, x, u);
SHFT(fv, fw, fx, fu);
}
else {
if(u < x) a = u; else b = u;
if(fu <= fw || w == x) {
v = w;
w = u;
fv = fw;
fw = fu;
}
else if(fu <= fv || v == x || v == w) {
v = u;
fv = fu;
}
}
}
Done = Standard_False;
return;
}
math_BrentMinimum::math_BrentMinimum(math_Function& F,
const Standard_Real Ax,
const Standard_Real Bx,
const Standard_Real Cx,
const Standard_Real TolX,
const Standard_Integer NbIterations,
const Standard_Real ZEPS) {
XTol = TolX;
EPSZ = ZEPS;
Itermax = NbIterations;
myF = Standard_False;
Perform(F, Ax, Bx, Cx);
}
// Constructeur d'initialisation des champs.
math_BrentMinimum::math_BrentMinimum(const Standard_Real TolX,
const Standard_Integer NbIterations,
const Standard_Real ZEPS) {
myF = Standard_False;
XTol = TolX;
EPSZ = ZEPS;
Itermax = NbIterations;
}
math_BrentMinimum::math_BrentMinimum(const Standard_Real TolX,
const Standard_Real Fbx,
const Standard_Integer NbIterations,
const Standard_Real ZEPS) {
fx = Fbx;
myF = Standard_True;
XTol = TolX;
EPSZ = ZEPS;
Itermax = NbIterations;
}
// Standard_Boolean math_BrentMinimum::IsSolutionReached(math_Function& F) {
Standard_Boolean math_BrentMinimum::IsSolutionReached(math_Function& ) {
Standard_Real xm = 0.5 * (a + b);
// modified by NIZHNY-MKK Mon Oct 3 17:45:57 2005.BEGIN
// Standard_Real tol = XTol * fabs(x) + EPSZ;
// return fabs(x - xm) <= 2.0 * tol - 0.5 * (b - a);
Standard_Real TwoTol = 2.0 *(XTol * fabs(x) + EPSZ);
return ((x <= (TwoTol + a)) && (x >= (b - TwoTol)));
// modified by NIZHNY-MKK Mon Oct 3 17:46:00 2005.END
}
void math_BrentMinimum::Dump(Standard_OStream& o) const {
o << "math_BrentMinimum ";
if(Done) {
o << " Status = Done \n";
o << " Location value = " << x <<"\n";
o << " Minimum value = " << fx << "\n";
o << " Number of iterations = " << iter <<"\n";
}
else {
o << " Status = not Done \n";
}
}

30
src/math/math_BrentMinimum.lxx Executable file
View File

@@ -0,0 +1,30 @@
// file math_BrentMinimum.lxx
#include <StdFail_NotDone.hxx>
inline Standard_Boolean math_BrentMinimum::IsDone() const { return Done; }
inline Standard_OStream& operator<< (Standard_OStream& o,
const math_BrentMinimum& Br)
{
Br.Dump(o);
return o;
}
inline Standard_Real math_BrentMinimum::Location() const{
StdFail_NotDone_Raise_if(!Done, " ");
return x;
}
inline Standard_Real math_BrentMinimum::Minimum() const{
StdFail_NotDone_Raise_if(!Done, " ");
return fx;
}
inline Standard_Integer math_BrentMinimum::NbIterations() const{
StdFail_NotDone_Raise_if(!Done, " ");
return iter;
}

View File

@@ -0,0 +1,32 @@
-- File: math_CompareOfValueAndWeight.cdl
-- Created: Tue Dec 20 13:24:41 2005
-- Author: Julia GERASIMOVA
-- <jgv@clubox>
---Copyright: Matra Datavision 2005
class CompareOfValueAndWeight from math
uses
ValueAndWeight from math
is
Create;
IsLower (me; Left, Right: ValueAndWeight)
---Level: Public
---Purpose: Returns True if <Left.Value()> is lower than <Right.Value()>.
returns Boolean from Standard;
IsGreater (me; Left, Right: ValueAndWeight)
---Level: Public
---Purpose: Returns True if <Left.Value()> is greater than <Right.Value()>.
returns Boolean from Standard;
IsEqual(me; Left, Right: ValueAndWeight)
---Level: Public
---Purpose: returns True when <Right> and <Left> are equal.
returns Boolean from Standard;
end;

View File

@@ -0,0 +1,41 @@
// File: math_CompareOfValueAndWeight.cxx
// Created: Tue Dec 20 13:30:54 2005
// Author: Julia GERASIMOVA
// <jgv@clubox>
#include <math_CompareOfValueAndWeight.ixx>
// -----------
// Create :
// -----------
math_CompareOfValueAndWeight::math_CompareOfValueAndWeight()
{
}
// -----------
// IsLower :
// -----------
Standard_Boolean math_CompareOfValueAndWeight::IsLower(const math_ValueAndWeight& Left,
const math_ValueAndWeight& Right) const
{
return (Left.Value() < Right.Value());
}
// -----------
// IsGreater :
// -----------
Standard_Boolean math_CompareOfValueAndWeight::IsGreater(const math_ValueAndWeight& Left,
const math_ValueAndWeight& Right) const
{
return (Left.Value() > Right.Value());
}
// -----------
// IsEqual :
// -----------
Standard_Boolean math_CompareOfValueAndWeight::IsEqual(const math_ValueAndWeight& Left,
const math_ValueAndWeight& Right) const
{
return (Left.Value() == Right.Value());
}

View File

@@ -0,0 +1,33 @@
-- File: math_ComputeGaussPointsAndWeights.cdl
-- Created: Mon Dec 19 12:41:51 2005
-- Author: Julia GERASIMOVA
-- <jgv@clubox>
---Copyright: Matra Datavision 2005
class ComputeGaussPointsAndWeights from math
uses
Vector from math,
HArray1OfReal from TColStd
is
Create(Number : Integer from Standard)
returns ComputeGaussPointsAndWeights;
IsDone(me)
returns Boolean from Standard;
Points(me)
returns Vector from math;
Weights(me)
returns Vector from math;
fields
myPoints : HArray1OfReal from TColStd;
myWeights : HArray1OfReal from TColStd;
myIsDone : Boolean from Standard;
end ComputeGaussPointsAndWeights;

View File

@@ -0,0 +1,92 @@
// File: math_ComputeGaussPointsAndWeights.cxx
// Created: Mon Dec 19 16:01:53 2005
// Author: Julia GERASIMOVA
// <jgv@clubox>
#include <math_ComputeGaussPointsAndWeights.ixx>
#include <math_EigenValuesSearcher.hxx>
#include <math_Array1OfValueAndWeight.hxx>
#include <math_CompareOfValueAndWeight.hxx>
#include <math_QuickSortOfValueAndWeight.hxx>
#include <Standard_ErrorHandler.hxx>
math_ComputeGaussPointsAndWeights::math_ComputeGaussPointsAndWeights(const Standard_Integer Number)
{
myIsDone = Standard_False;
try {
myPoints = new TColStd_HArray1OfReal(1, Number);
myWeights = new TColStd_HArray1OfReal(1, Number);
Standard_Integer i;
TColStd_Array1OfReal aDiag(1, Number);
TColStd_Array1OfReal aSubDiag(1, Number);
//Initialization of a real symmetric tridiagonal matrix for
//computation of Gauss quadrature.
for (i = 1; i <= Number; i++) {
aDiag(i) = 0.;
if (i == 1)
aSubDiag(i) = 0.;
else {
Standard_Integer sqrIm1 = (i-1)*(i-1);
aSubDiag(i) = sqrIm1/(4.*sqrIm1 - 1);
aSubDiag(i) = Sqrt(aSubDiag(i));
}
}
// Compute eigen values.
math_EigenValuesSearcher EVsearch(aDiag, aSubDiag);
if (EVsearch.IsDone()) {
math_Array1OfValueAndWeight VWarray(1, Number);
for (i = 1; i <= Number; i++) {
math_Vector anEigenVector = EVsearch.EigenVector(i);
Standard_Real aWeight = anEigenVector(1);
aWeight = 2. * aWeight * aWeight;
math_ValueAndWeight EVW( EVsearch.EigenValue(i), aWeight );
VWarray(i) = EVW;
}
math_CompareOfValueAndWeight theComparator;
math_QuickSortOfValueAndWeight::Sort(VWarray, theComparator);
for (i = 1; i <= Number; i++) {
myPoints->ChangeValue(i) = VWarray(i).Value();
myWeights->ChangeValue(i) = VWarray(i).Weight();
}
myIsDone = Standard_True;
}
} catch (Standard_Failure) {
}
}
Standard_Boolean math_ComputeGaussPointsAndWeights::IsDone() const
{
return myIsDone;
}
math_Vector math_ComputeGaussPointsAndWeights::Points() const
{
Standard_Integer Number = myPoints->Length();
math_Vector thePoints(1, Number);
for (Standard_Integer i = 1; i <= Number; i++)
thePoints(i) = myPoints->Value(i);
return thePoints;
}
math_Vector math_ComputeGaussPointsAndWeights::Weights() const
{
Standard_Integer Number = myWeights->Length();
math_Vector theWeights(1, Number);
for (Standard_Integer i = 1; i <= Number; i++)
theWeights(i) = myWeights->Value(i);
return theWeights;
}

View File

@@ -0,0 +1,33 @@
-- File: math_ComputeKronrodPointsAndWeights.cdl
-- Created: Wed Dec 21 18:07:18 2005
-- Author: Julia GERASIMOVA
-- <jgv@clubox>
---Copyright: Matra Datavision 2005
class ComputeKronrodPointsAndWeights from math
uses
Vector from math,
HArray1OfReal from TColStd
is
Create(Number : Integer from Standard)
returns ComputeKronrodPointsAndWeights;
IsDone(me)
returns Boolean from Standard;
Points(me)
returns Vector from math;
Weights(me)
returns Vector from math;
fields
myPoints : HArray1OfReal from TColStd;
myWeights : HArray1OfReal from TColStd;
myIsDone : Boolean from Standard;
end ComputeKronrodPointsAndWeights;

View File

@@ -0,0 +1,184 @@
// File: math_ComputeKronrodPointsAndWeights.cxx
// Created: Wed Dec 21 18:11:52 2005
// Author: Julia GERASIMOVA
// <jgv@clubox>
#include <math_ComputeKronrodPointsAndWeights.ixx>
#include <math_EigenValuesSearcher.hxx>
#include <math_Array1OfValueAndWeight.hxx>
#include <math_CompareOfValueAndWeight.hxx>
#include <math_QuickSortOfValueAndWeight.hxx>
#include <Standard_ErrorHandler.hxx>
math_ComputeKronrodPointsAndWeights::math_ComputeKronrodPointsAndWeights(const Standard_Integer Number)
{
myIsDone = Standard_False;
try {
Standard_Integer i, j;
Standard_Integer a2NP1 = 2*Number + 1;
myPoints = new TColStd_HArray1OfReal(1, a2NP1);
myWeights = new TColStd_HArray1OfReal(1, a2NP1);
TColStd_Array1OfReal aDiag(1, a2NP1);
TColStd_Array1OfReal aSubDiag(1, a2NP1);
// Initialize symmetric tridiagonal matrix.
Standard_Integer n = Number;
Standard_Integer aKronrodN = 2*Number + 1;
Standard_Integer a3KN2p1 = Min(3*(Number + 1)/2 + 1, aKronrodN);
for (i = 1; i <= a3KN2p1; i++) {
aDiag(i) = 0.;
if (i == 1)
aSubDiag(i) = 0.;
else {
Standard_Integer sqrIm1 = (i-1)*(i-1);
aSubDiag(i) = sqrIm1/(4.*sqrIm1 - 1);
}
}
for (i = a3KN2p1 + 1; i <= aKronrodN; i++) {
aDiag(i) = 0.;
aSubDiag(i) = 0.;
}
// Initialization of temporary data structures.
Standard_Integer aNd2 = Number/2;
Standard_Real *s = new Standard_Real[aNd2 + 2];
Standard_Real *t = new Standard_Real[aNd2 + 2];
Standard_Real *ss = s++;
Standard_Real *tt = t++;
for (i = -1; i <= aNd2; i++) {
s[i] = 0.;
t[i] = 0.;
}
// Generation of Jacobi-Kronrod matrix.
Standard_Real *aa = new Standard_Real [a2NP1+1];
Standard_Real *bb = new Standard_Real [a2NP1+1];
for (i = 1; i <= a2NP1; i++) {
aa[i] = aDiag(i);
bb[i] = aSubDiag(i);
}
Standard_Real *ptrtmp;
Standard_Real u;
Standard_Integer m;
Standard_Integer k;
Standard_Integer l;
Standard_Real *a = aa+1;
Standard_Real *b = bb+1;
// Eastward phase.
t[0] = b[Number + 1];
for (m = 0; m <= n - 2; m++) {
u = 0;
for (k = (m + 1)/2; k >= 0; k--) {
l = m - k;
u += (a[k + n + 1] - a[l])*t[k] + b[k + n + 1]*s[k - 1] - b[l]*s[k];
s[k] = u;
}
ptrtmp = t;
t = s;
s = ptrtmp;
}
for (j = aNd2; j >= 0; j--)
s[j] = s[j - 1];
// Southward phase.
for (m = n - 1; m <= 2*n - 3; m++) {
u = 0;
for (k = m + 1 - n; k <= (m - 1)/2; k++) {
l = m - k;
j = n - 1 - l;
u += -(a[k + n + 1] - a[l])*t[j] - b[k + n + 1]*s[j] + b[l]*s[j + 1];
s[j] = u;
}
if (m % 2 == 0) {
k = m/2;
a[k + n + 1] = a[k] + (s[j] - b[k + n + 1]*s[j + 1])/ t[j + 1];
} else {
k = (m + 1)/2;
b[k + n + 1] = s[j]/s[j + 1];
}
ptrtmp = t;
t = s;
s = ptrtmp;
}
// Termination phase.
a[2*Number] = a[n - 1] - b[2*Number]*s[0]/t[0];
delete [] ss;
delete [] tt;
for (i = 1; i <= a2NP1; i++) {
aDiag(i) = aa[i];
aSubDiag(i) = bb[i];
}
delete [] aa;
delete [] bb;
for (i = 1; i <= a2NP1; i++)
aSubDiag(i) = Sqrt(aSubDiag(i));
// Compute eigen values.
math_EigenValuesSearcher EVsearch(aDiag, aSubDiag);
if (EVsearch.IsDone()) {
math_Array1OfValueAndWeight VWarray(1, a2NP1);
for (i = 1; i <= a2NP1; i++) {
math_Vector anEigenVector = EVsearch.EigenVector(i);
Standard_Real aWeight = anEigenVector(1);
aWeight = 2. * aWeight * aWeight;
math_ValueAndWeight EVW( EVsearch.EigenValue(i), aWeight );
VWarray(i) = EVW;
}
math_CompareOfValueAndWeight theComparator;
math_QuickSortOfValueAndWeight::Sort(VWarray, theComparator);
for (i = 1; i <= a2NP1; i++) {
myPoints->ChangeValue(i) = VWarray(i).Value();
myWeights->ChangeValue(i) = VWarray(i).Weight();
}
myIsDone = Standard_True;
}
} catch (Standard_Failure) {
}
}
Standard_Boolean math_ComputeKronrodPointsAndWeights::IsDone() const
{
return myIsDone;
}
math_Vector math_ComputeKronrodPointsAndWeights::Points() const
{
Standard_Integer Number = myPoints->Length();
math_Vector thePoints(1, Number);
for (Standard_Integer i = 1; i <= Number; i++)
thePoints(i) = myPoints->Value(i);
return thePoints;
}
math_Vector math_ComputeKronrodPointsAndWeights::Weights() const
{
Standard_Integer Number = myWeights->Length();
math_Vector theWeights(1, Number);
for (Standard_Integer i = 1; i <= Number; i++)
theWeights(i) = myWeights->Value(i);
return theWeights;
}

109
src/math/math_Crout.cdl Executable file
View File

@@ -0,0 +1,109 @@
-- File: Crout.cdl
-- Created: Thu Aug 22 10:57:59 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class Crout from math
---Purpose: This class implements the Crout algorithm used to solve a
-- system A*X = B where A is a symmetric matrix. It can be used to
-- invert a symmetric matrix.
-- This algorithm is similar to Gauss but is faster than Gauss.
-- Only the inferior triangle of A and the diagonal can be given.
uses Matrix from math,
Vector from math,
OStream from Standard
raises NotDone from StdFail,
NotSquare from math,
DimensionError from Standard
is
Create(A: Matrix; MinPivot: Real = 1.0e-20)
---Purpose: Given an input matrix A, this algorithm inverts A by the
-- Crout algorithm. The user can give only the inferior
-- triangle for the implementation.
-- A can be decomposed like this:
-- A = L * D * T(L) where L is triangular inferior and D is
-- diagonal.
-- If one element of A is less than MinPivot, A is
-- considered as singular.
-- Exception NotSquare is raised if A is not a square matrix.
returns Crout
raises NotSquare;
IsDone(me)
---Purpose: Returns True if all has been correctly done.
---C++: inline
returns Boolean
is static;
Solve(me; B: Vector; X: out Vector)
---Purpose: Given an input vector <B>, this routine returns the
-- solution of the set of linear equations A . X = B.
-- Exception NotDone is raised if the decomposition was not
-- done successfully.
-- Exception DimensionError is raised if the range of B is
-- not equal to the rowrange of A.
raises NotDone,
DimensionError
is static;
Inverse(me)
---Purpose: returns the inverse matrix of A. Only the inferior
-- triangle is returned.
-- Exception NotDone is raised if NotDone.
---C++: inline
---C++: return const&
returns Matrix
raises NotDone
is static;
Invert(me; Inv: out Matrix)
---Purpose: returns in Inv the inverse matrix of A. Only the inferior
-- triangle is returned.
-- Exception NotDone is raised if NotDone.
---C++: inline
raises NotDone
is static;
Determinant(me)
---Purpose: Returns the value of the determinant of the previously LU
-- decomposed matrix A. Zero is returned if the matrix A is considered as singular.
-- Exceptions
-- StdFail_NotDone if the algorithm fails (and IsDone returns false).
---C++: inline
returns Real
raises NotDone
is static;
Dump(me; o: in out OStream)
---Purpose: Prints on the stream o information on the current state
-- of the object.
is static;
fields
InvA: Matrix;
Done: Boolean;
Det: Real;
end Crout;

127
src/math/math_Crout.cxx Executable file
View File

@@ -0,0 +1,127 @@
//static const char* sccsid = "@(#)math_Crout.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
// File math_Crout.cxx
// lpa le 20/08/91
//#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#define No_Standard_DimensionError
//#endif
#include <math_Crout.ixx>
#include <math_NotSquare.hxx>
#include <StdFail_NotDone.hxx>
#include <math_Vector.hxx>
math_Crout::math_Crout(const math_Matrix& A, const Standard_Real MinPivot):
InvA(1, A.RowNumber(), 1, A.ColNumber())
{
Standard_Integer i,j,k;
Standard_Integer Nctl = A.RowNumber();
Standard_Integer lowr = A.LowerRow(), lowc = A.LowerCol();
Standard_Real scale;
math_Matrix L(1, Nctl, 1, Nctl);
math_Vector Diag(1, Nctl);
math_NotSquare_Raise_if(Nctl != A.ColNumber(), " ");
Det = 1;
for (i =1; i <= Nctl; i++) {
for (j = 1; j <= i -1; j++) {
scale = 0.0;
for (k = 1; k <= j-1; k++) {
scale += L(i,k)*L(j,k)*Diag(k);
}
L(i,j) = (A(i+lowr-1,j+lowc-1)-scale)/Diag(j);
}
scale = 0.0;
for (k = 1; k <= i-1; k++) {
scale += L(i,k)*L(i,k)*Diag(k);
}
Diag(i) = A(i+lowr-1,i+lowc-1)-scale;
Det *= Diag(i);
if (Abs(Diag(i)) <= MinPivot) {
Done = Standard_False;
return;
}
L(i,i) = 1.0;
}
// Calcul de l inverse de L:
//==========================
L(1,1) = 1./L(1,1);
for (i = 2; i <= Nctl; i++) {
for (k = 1; k <= i-1; k++) {
scale = 0.0;
for (j = k; j <= i-1; j++) {
scale += L(i,j)*L(j,k);
}
L(i,k) = -scale/L(i,i);
}
L(i,i) = 1./L(i,i);
}
// Calcul de l inverse de Mat:
//============================
for (j = 1; j <= Nctl; j++) {
scale = L(j,j)*L(j,j)/Diag(j);
for (k = j+1; k <= Nctl; k++) {
scale += L(k,j) *L(k,j)/Diag(k);
}
InvA(j,j) = scale;
for (i = j+1; i <= Nctl; i++) {
scale = L(i,j) *L(i,i)/Diag(i);
for (k = i+1; k <= Nctl; k++) {
scale += L(k,j)*L(k,i)/Diag(k);
}
InvA(i,j) = scale;
}
}
Done = Standard_True;
}
void math_Crout::Solve(const math_Vector& B, math_Vector& X) const
{
StdFail_NotDone_Raise_if(!Done, " ");
Standard_DimensionError_Raise_if((B.Length() != InvA.RowNumber()) ||
(X.Length() != B.Length()), " ");
Standard_Integer n = InvA.RowNumber();
Standard_Integer lowb = B.Lower(), lowx = X.Lower();
Standard_Integer i, j;
for (i = 1; i <= n; i++) {
X(i+lowx-1) = InvA(i, 1)*B(1+lowb-1);
for ( j = 2; j <= i; j++) {
X(i+lowx-1) += InvA(i, j)*B(j+lowb-1);
}
for (j = i+1; j <= n; j++) {
X(i+lowx-1) += InvA(j,i)*B(j+lowb-1);
}
}
}
void math_Crout::Dump(Standard_OStream& o) const
{
o << "math_Crout ";
if(Done) {
o << " Status = Done \n";
}
else {
o << " Status = not Done \n";
}
}

31
src/math/math_Crout.lxx Executable file
View File

@@ -0,0 +1,31 @@
// File math_Crout.lxx
#include <StdFail_NotDone.hxx>
inline Standard_Boolean math_Crout::IsDone() const { return Done; }
inline Standard_OStream& operator<< (Standard_OStream& o,
const math_Crout& C)
{
C.Dump(o);
return o;
}
inline Standard_Real math_Crout::Determinant() const {
StdFail_NotDone_Raise_if(!Done, " ");
return Det;
}
inline const math_Matrix& math_Crout::Inverse() const {
StdFail_NotDone_Raise_if(!Done, " ");
return InvA;
}
inline void math_Crout::Invert(math_Matrix& Inv) const {
StdFail_NotDone_Raise_if(!Done, " ");
Inv = InvA;
}

View File

@@ -0,0 +1,113 @@
-- File: DirectPolynomialRoots.cdl
-- Created: Mon May 13 16:47:42 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class DirectPolynomialRoots from math
---Purpose:
-- This class implements the calculation of all the real roots of a real
-- polynomial of degree <= 4 using a direct method. Once found,
-- the roots are polished using the Newton method.
uses OStream from Standard
raises RangeError from Standard,
InfiniteSolutions from StdFail
is
Create(A, B, C, D, E: Real)
---Purpose:
-- computes all the real roots of the polynomial
-- Ax4 + Bx3 + Cx2 + Dx + E using a direct method.
returns DirectPolynomialRoots;
Create(A, B, C, D: Real)
---Purpose:
-- computes all the real roots of the polynomial
-- Ax3 + Bx2 + Cx + D using a direct method.
returns DirectPolynomialRoots;
Create(A, B, C: Real)
---Purpose:
-- computes all the real roots of the polynomial
-- Ax2 + Bx + C using a direct method.
returns DirectPolynomialRoots;
Create(A, B: Real)
---Purpose:
-- computes the real root of the polynomial Ax + B.
returns DirectPolynomialRoots;
Solve(me: in out; A, B, C, D, E: Real)
is static protected;
Solve(me: in out; A, B, C, D: Real)
is static protected;
Solve(me: in out; A, B, C: Real)
is static protected;
Solve(me: in out; A, B: Real)
is static protected;
IsDone(me)
---Purpose: Returns true if the computations are successful, otherwise returns false.
---C++: inline
returns Boolean
is static;
InfiniteRoots(me)
---Purpose: Returns true if there is an infinity of roots, otherwise returns false.
---C++: inline
returns Boolean
is static;
NbSolutions(me)
---Purpose: returns the number of solutions.
-- An exception is raised if there are an infinity of roots.
---C++: inline
returns Integer
raises InfiniteSolutions
is static;
Value(me; Nieme: Integer)
---Purpose: returns the value of the Nieme root.
-- An exception is raised if there are an infinity of roots.
-- Exception RangeError is raised if Nieme is < 1
-- or Nieme > NbSolutions.
---C++: inline
returns Real
raises InfiniteSolutions, RangeError
is static;
Dump(me; o: in out OStream)
---Purpose: Prints on the stream o information on the current state
-- of the object.
-- Is used to redefine the operator <<.
is static;
fields
Done: Boolean;
InfiniteStatus: Boolean;
NbSol: Integer;
TheRoots: Real[4];
end DirectPolynomialRoots;

View File

@@ -0,0 +1,526 @@
//static const char* sccsid = "@(#)math_DirectPolynomialRoots.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
//#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#define No_Standard_DimensionError
//#endif
#include <math_DirectPolynomialRoots.ixx>
#include <Standard_RangeError.hxx>
#include <StdFail_InfiniteSolutions.hxx>
// Reference pour solution equation 3ieme degre et 2ieme degre :
// ALGORITHMES NUMERIQUES ANALYSE ET MISE EN OEUVRE, tome 2
// (equations et systemes non lineaires)
//
// J. VIGNES editions TECHNIP.
const Standard_Real ZERO = 1.0e-30;
const Standard_Real EPSILON = RealEpsilon();
const Standard_Real RADIX = 2;
const Standard_Real Un_Sur_Log_RADIX = 1.0/log(2.0);
static Standard_Real Value(const Standard_Integer N, Standard_Real *Poly, const Standard_Real X) {
Standard_Real Result = Poly[0];
for(Standard_Integer Index = 1; Index < N; Index++) {
Result = Result * X + Poly[Index];
}
return Result;
}
static void Values(const Standard_Integer N, Standard_Real *Poly, const Standard_Real X,
Standard_Real& Val, Standard_Real& Der) {
Val = Poly[0] * X + Poly[1];
Der = Poly[0];
for(Standard_Integer Index = 2; Index < N; Index++) {
Der = Der * X + Val;
Val = Val * X + Poly[Index];
}
}
static Standard_Real Improve(const Standard_Integer N, Standard_Real *Poly, const Standard_Real IniSol) {
Standard_Real Val, Der, Delta;
Standard_Real Sol = IniSol;
Standard_Real IniVal = Value(N, Poly, IniSol);
Standard_Integer Index;
// cout << "Improve\n";
for(Index = 1; Index < 10; Index++) {
Values(N, Poly, Sol, Val, Der);
if(Abs(Der) <= ZERO) break;
Delta = - Val / Der;
if(Abs(Delta) <= EPSILON * Abs(Sol)) break;
Sol = Sol + Delta;
// cout << " Iter = " << Index << " Delta = " << Delta
// << " Val = " << Val << " Der = " << Der << "\n";
}
if(Abs(Val) <= Abs(IniVal)) {
return Sol;
}
else {
return IniSol;
}
}
Standard_Real Improve(const Standard_Real A, const Standard_Real B, const Standard_Real C,
const Standard_Real D, const Standard_Real E, const Standard_Real IniSol) {
Standard_Real Poly[5];
Poly[0] = A;
Poly[1] = B;
Poly[2] = C;
Poly[3] = D;
Poly[4] = E;
return Improve(5, Poly, IniSol);
}
Standard_Real Improve(const Standard_Real A, const Standard_Real B,
const Standard_Real C, const Standard_Real D, const Standard_Real IniSol) {
Standard_Real Poly[4];
Poly[0] = A;
Poly[1] = B;
Poly[2] = C;
Poly[3] = D;
return Improve(4, Poly, IniSol);
}
Standard_Real Improve(const Standard_Real A, const Standard_Real B,
const Standard_Real C, const Standard_Real IniSol) {
Standard_Real Poly[3];
Poly[0] = A;
Poly[1] = B;
Poly[2] = C;
return Improve(3, Poly, IniSol);
}
Standard_Integer BaseExponent(const Standard_Real X) {
if(X > 1.0) {
return (Standard_Integer)(log(X) * Un_Sur_Log_RADIX);
}
else if(X < -1.0) {
return (Standard_Integer)(-log(-X) * Un_Sur_Log_RADIX);
}
else {
return 0;
}
}
math_DirectPolynomialRoots::math_DirectPolynomialRoots(const Standard_Real A,
const Standard_Real B,
const Standard_Real C,
const Standard_Real D,
const Standard_Real E) {
InfiniteStatus = Standard_False;
Done = Standard_True;
Solve(A, B, C, D, E);
}
math_DirectPolynomialRoots::math_DirectPolynomialRoots(const Standard_Real A,
const Standard_Real B,
const Standard_Real C,
const Standard_Real D) {
Done = Standard_True;
InfiniteStatus = Standard_False;
Solve(A, B, C, D);
}
math_DirectPolynomialRoots::math_DirectPolynomialRoots(const Standard_Real A,
const Standard_Real B,
const Standard_Real C) {
Done = Standard_True;
InfiniteStatus = Standard_False;
Solve(A, B, C);
}
math_DirectPolynomialRoots::math_DirectPolynomialRoots(const Standard_Real A,
const Standard_Real B) {
Done = Standard_True;
InfiniteStatus = Standard_False;
Solve(A, B);
}
void math_DirectPolynomialRoots::Solve(const Standard_Real a,
const Standard_Real b,
const Standard_Real c,
const Standard_Real d,
const Standard_Real e) {
if(Abs(a) <= ZERO) {
Solve(b, c, d, e);
return;
}
//// modified by jgv, 22.01.09 ////
Standard_Real aZero = ZERO;
Standard_Real Abs_b = Abs(b), Abs_c = Abs(c), Abs_d = Abs(d), Abs_e = Abs(e);
if (Abs_b > aZero)
aZero = Abs_b;
if (Abs_c > aZero)
aZero = Abs_c;
if (Abs_d > aZero)
aZero = Abs_d;
if (Abs_e > aZero)
aZero = Abs_e;
if (aZero > ZERO)
aZero = Epsilon(100.*aZero);
if(Abs(a) <= aZero) {
Standard_Real aZero1000 = 1000.*aZero;
Standard_Boolean with_a = Standard_False;
if (Abs_b > ZERO && Abs_b <= aZero1000)
with_a = Standard_True;
if (Abs_c > ZERO && Abs_c <= aZero1000)
with_a = Standard_True;
if (Abs_d > ZERO && Abs_d <= aZero1000)
with_a = Standard_True;
if (Abs_e > ZERO && Abs_e <= aZero1000)
with_a = Standard_True;
if (!with_a)
{
Solve(b, c, d, e);
return;
}
}
///////////////////////////////////
Standard_Real A, B, C, D, R3, S3, T3, Q3, Y0, P0, Q0, P, Q, P1, Q1;
Standard_Real Discr, Sdiscr;
Standard_Integer Index;
Standard_Integer Exp;
Standard_Real PowRadix1,PowRadix2;
A = b / a;
B = c / a;
C = d / a;
D = e / a;
Exp = BaseExponent(D) / 4;
//--
//-- A = A / pow(RADIX, Exp);
//-- B = B / pow(RADIX, 2 * Exp);
//-- C = C / pow(RADIX, 3 * Exp);
//-- D = D / pow(RADIX, 4 * Exp);
PowRadix1 = pow(RADIX,Exp);
A/= PowRadix1; PowRadix2 = PowRadix1 * PowRadix1;
B/= PowRadix2;
C/= PowRadix2 * PowRadix1;
D/= PowRadix2 * PowRadix2;
//--
R3 = -B;
S3 = A * C - 4.0 * D;
T3 = D * (4.0 * B - A * A) - C * C;
Q3 = 1.0;
math_DirectPolynomialRoots Sol3(Q3, R3, S3, T3);
//-- ################################################################################
if(Sol3.IsDone() == Standard_False) { Done = Standard_False; return; }
//-- ################################################################################
Y0 = Sol3.Value(1);
for(Index = 2; Index <= Sol3.NbSolutions(); Index++) {
if(Sol3.Value(Index) > Y0) Y0 = Sol3.Value(Index);
}
Discr = A * Y0 * 0.5 - C;
if(Discr >= 0.0) {
Sdiscr = 1.0;
}
else {
Sdiscr = -1.0;
}
P0 = A * A * 0.25 - B + Y0;
if(P0 < 0.0) P0 = 0.0;
P0 = sqrt(P0);
Q0 = Y0 * Y0 * 0.25 - D;
if(Q0 < 0.0) Q0 = 0.0;
Q0 = sqrt(Q0);
Standard_Real Ademi = A * 0.5;
Standard_Real Ydemi = Y0 * 0.5;
Standard_Real SdiscrQ0 = Sdiscr * Q0;
P = Ademi + P0;
Q = Ydemi + SdiscrQ0;
P1 = Ademi - P0;
Q1 = Ydemi - SdiscrQ0;
// Modified by skv - Wed Apr 14 16:05:24 2004 IDEM(Airbus) Begin
Standard_Real eps;
eps = Epsilon(100.*Max(Ademi, P0));
if (Abs(P) <= eps)
P = 0.;
if (Abs(P1) <= eps)
P1 = 0.;
eps = Epsilon(100.*Max(Ydemi, SdiscrQ0));
if (Abs(Q) <= eps)
Q = 0.;
if (Abs(Q1) <= eps)
Q1 = 0.;
// Modified by skv - Wed Apr 14 16:05:24 2004 IDEM(Airbus) End
Ademi = 1.0;
math_DirectPolynomialRoots ASol2(Ademi, P, Q);
//-- ################################################################################
if(ASol2.IsDone() == Standard_False) { Done = Standard_False; return; }
//-- ################################################################################
math_DirectPolynomialRoots BSol2(Ademi, P1, Q1);
//-- ################################################################################
if(BSol2.IsDone() == Standard_False) { Done = Standard_False; return; }
//-- ################################################################################
NbSol = ASol2.NbSolutions() + BSol2.NbSolutions();
for(Index = 0; Index < ASol2.NbSolutions(); Index++) {
TheRoots[Index] = ASol2.TheRoots[Index];
}
for(Index = 0; Index < BSol2.NbSolutions(); Index++) {
TheRoots[ASol2.NbSolutions() + Index] = BSol2.TheRoots[Index];
}
for(Index = 0; Index < NbSol; Index++) {
TheRoots[Index] = TheRoots[Index] * PowRadix1;
TheRoots[Index] = Improve(a, b, c, d, e, TheRoots[Index]);
}
}
void math_DirectPolynomialRoots::Solve(const Standard_Real A,
const Standard_Real B,
const Standard_Real C,
const Standard_Real D) {
if(Abs(A) <= ZERO) {
Solve(B, C, D);
return;
}
Standard_Real Beta, Gamma, Del, P1, P2, P, Ep, Q1, Q2, Q3, Q, Eq, A1, A2, Discr;
Standard_Real Sigma, Psi, D1, D2, Sb, Omega, Sp3, Y1, Dbg, Sdbg, Den1, Den2;
Standard_Real U, H, Sq;
Standard_Integer Exp;
Beta = B / A;
Gamma = C / A;
Del = D / A;
Exp = BaseExponent(Del) / 3;
Standard_Real PowRadix1 = pow(RADIX,Exp);
Standard_Real PowRadix2 = PowRadix1*PowRadix1;
Beta/= PowRadix1;
Gamma/= PowRadix2;
Del/= PowRadix2 * PowRadix1;
//-- Beta = Beta / pow(RADIX, Exp);
//-- Gamma = Gamma / pow(RADIX, 2 * Exp);
//-- Del = Del / pow(RADIX, 3 * Exp);
P1 = Gamma;
P2 = - (Beta * Beta) / 3.0;
P = P1 + P2;
Ep = 5.0 * EPSILON * (Abs(P1) + Abs(P2));
if(Abs(P) <= Ep) P = 0.0;
Q1 = Del;
Q2 = - Beta * Gamma / 3.0;
Q3 = 2.0 * (Beta * Beta * Beta) / 27.0;
Q = Q1 + Q2 + Q3;
Eq = 10.0 * EPSILON * (Abs(Q1) + Abs(Q2) + Abs(Q3));
if(Abs(Q) <= Eq) Q = 0.0;
//-- ############################################################
Standard_Real AbsP = P; if(P<0.0) AbsP = -P;
if(AbsP>1e+80) { Done = Standard_False; return; }
//-- ############################################################
A1 = (P * P * P) / 27.0;
A2 = (Q * Q) / 4.0;
Discr = A1 + A2;
if(P < 0.0) {
Sigma = - Q2 - Q3;
Psi = Gamma * Gamma * (4.0 * Gamma - Beta * Beta) / 27.0;
if(Sigma >= 0.0) {
D1 = Sigma + 2.0 * sqrt(-A1);
}
else {
D1 = Sigma - 2.0 * sqrt(-A1);
}
D2 = Psi / D1;
Discr = 0.0;
if(Abs(Del - D1) >= 18.0 * EPSILON * (Abs(Del) + Abs(D1)) &&
Abs(Del - D2) >= 24.0 * EPSILON * (Abs(Del) + Abs(D2))) {
Discr = (Del - D1) * (Del - D2) / 4.0;
}
}
if(Beta >= 0.0) {
Sb = 1.0;
}
else {
Sb = -1.0;
}
if(Discr < 0.0) {
NbSol = 3;
if(Beta == 0.0 && Q == 0.0) {
TheRoots[0] = sqrt(-P);
TheRoots[1] = -TheRoots[0];
TheRoots[2] = 0.0;
}
else {
Omega = atan(0.5 * Q / sqrt(- Discr));
Sp3 = sqrt(-P / 3.0);
Y1 = -2.0 * Sb * Sp3 * cos(PI / 6.0 - Sb * Omega / 3.0);
TheRoots[0] = - Beta / 3.0 + Y1;
if(Beta * Q <= 0.0) {
TheRoots[1] = - Beta / 3.0 + 2.0 * Sp3 * sin(Omega / 3.0);
}
else {
Dbg = Del - Beta * Gamma;
if(Dbg >= 0.0) {
Sdbg = 1.0;
}
else {
Sdbg = -1.0;
}
Den1 = 8.0 * Beta * Beta / 9.0 - 4.0 * Beta * Y1 / 3.0
- 2.0 * Q / Y1;
Den2 = 2.0 * Y1 * Y1 - Q / Y1;
TheRoots[1] = Dbg / Den1 + Sdbg * sqrt(-27.0 * Discr) / Den2;
}
TheRoots[2] = - Del / (TheRoots[0] * TheRoots[1]);
}
}
else if(Discr > 0.0) {
NbSol = 1;
U = sqrt(Discr) + Abs(Q / 2.0);
if(U >= 0.0) {
U = pow(U, 1.0 / 3.0);
}
else {
U = - pow(Abs(U), 1.0 / 3.0);
}
if(P >= 0.0) {
H = U * U + P / 3.0 + (P / U) * (P / U) / 9.0;
}
else {
H = U * Abs(Q) / (U * U - P / 3.0);
}
if(Beta * Q >= 0.0) {
if(Abs(H) <= RealSmall() && Abs(Q) <= RealSmall()) {
TheRoots[0] = - Beta / 3.0 - U + P / (3.0 * U);
}
else {
TheRoots[0] = - Beta / 3.0 - Q / H;
}
}
else {
TheRoots[0] = - Del / (Beta * Beta / 9.0 + H - Beta * Q / (3.0 * H));
}
}
else {
NbSol = 3;
if(Q >= 0.0) {
Sq = 1.0;
}
else {
Sq = -1.0;
}
Sp3 = sqrt(-P / 3.0);
if(Beta * Q <= 0.0) {
TheRoots[0] = -Beta / 3.0 + Sq * Sp3;
TheRoots[1] = TheRoots[0];
if(Beta * Q == 0.0) {
TheRoots[2] = -Beta / 3.0 - 2.0 * Sq * Sp3;
}
else {
TheRoots[2] = - Del / (TheRoots[0] * TheRoots[1]);
}
}
else {
TheRoots[0] = -Gamma / (Beta + 3.0 * Sq * Sp3);
TheRoots[1] = TheRoots[0];
TheRoots[2] = -Beta / 3.0 - 2.0 * Sq * Sp3;
}
}
for(Standard_Integer Index = 0; Index < NbSol; Index++) {
TheRoots[Index] = TheRoots[Index] * pow(RADIX, Exp);
TheRoots[Index] = Improve(A, B, C, D, TheRoots[Index]);
}
}
void math_DirectPolynomialRoots::Solve(const Standard_Real A,
const Standard_Real B,
const Standard_Real C) {
if(Abs(A) <= ZERO) {
Solve(B, C);
return;
}
Standard_Real EpsD = 3.0 * EPSILON * (B * B + Abs(4.0 * A * C));
Standard_Real Discrim = B * B - 4.0 * A * C;
if(Abs(Discrim) <= EpsD) Discrim = 0.0;
if(Discrim < 0.0) {
NbSol = 0;
}
else if(Discrim == 0.0) {
NbSol = 2;
TheRoots[0] = -0.5 * B / A;
TheRoots[0] = Improve(A, B, C, TheRoots[0]);
TheRoots[1] = TheRoots[0];
}
else {
NbSol = 2;
if(B > 0.0) {
TheRoots[0] = - (B + sqrt(Discrim)) / (2.0 * A);
}
else {
TheRoots[0] = - (B - sqrt(Discrim)) / (2.0 * A);
}
TheRoots[0] = Improve(A, B, C, TheRoots[0]);
TheRoots[1] = C / (A * TheRoots[0]);
TheRoots[1] = Improve(A, B, C, TheRoots[1]);
}
}
void math_DirectPolynomialRoots::Solve(const Standard_Real A,
const Standard_Real B) {
if(Abs(A) <= ZERO) {
if (Abs(B) <= ZERO) {
InfiniteStatus = Standard_True;
return;
}
NbSol = 0;
return;
}
NbSol = 1;
TheRoots[0] = -B / A;
}
void math_DirectPolynomialRoots::Dump(Standard_OStream& o) const {
o << "math_DirectPolynomialRoots ";
if (!Done) {
o <<" Not Done \n";
}
else if(InfiniteStatus) {
o << " Status = Infinity Roots \n";
}
else if (!InfiniteStatus) {
o << " Status = Not Infinity Roots \n";
o << " Number of solutions = " << NbSol <<"\n";
for (Standard_Integer i = 1; i <= NbSol; i++) {
o << " Solution number " << i << " = " << TheRoots[i-1] <<"\n";
}
}
}

View File

@@ -0,0 +1,38 @@
// file math_DirectPolynomialRoots.lxx
#include <Standard_RangeError.hxx>
#include <StdFail_InfiniteSolutions.hxx>
inline Standard_Boolean math_DirectPolynomialRoots::IsDone() const
{return Done;}
inline Standard_Boolean math_DirectPolynomialRoots::InfiniteRoots() const
{return InfiniteStatus; }
inline Standard_OStream& operator<<(Standard_OStream& o,
const math_DirectPolynomialRoots& D)
{
D.Dump(o);
return o;
}
inline Standard_Integer math_DirectPolynomialRoots::NbSolutions() const
{
StdFail_InfiniteSolutions_Raise_if(InfiniteStatus, " ");
return NbSol;
}
inline Standard_Real math_DirectPolynomialRoots::Value(const Standard_Integer Nieme) const
{
StdFail_InfiniteSolutions_Raise_if(InfiniteStatus, " ");
Standard_RangeError_Raise_if((Nieme < 0) ||
(Nieme > NbSol), " ");
return TheRoots[Nieme - 1];
}

61
src/math/math_DoubleTab.cdl Executable file
View File

@@ -0,0 +1,61 @@
-- File: DoubleTab.cdl
-- Created: Fri Feb 7 09:26:29 1992
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1992
generic class DoubleTab from math (Item as any)
uses Address from Standard
is
Create(LowerRow, UpperRow, LowerCol, UpperCol: Integer)
returns DoubleTab;
Create(Tab : Item; LowerRow, UpperRow, LowerCol, UpperCol: Integer)
returns DoubleTab;
Init(me : in out; InitValue: Item) is static;
Create(Other: DoubleTab)
returns DoubleTab;
Allocate(me : in out) is private;
Copy(me; Other: in out DoubleTab)
---C++: inline
is static;
SetLowerRow(me: in out; LowerRow: Integer)
is static;
SetLowerCol(me: in out; LowerCol: Integer)
is static;
Value(me; RowIndex, ColIndex: Integer)
---C++: alias operator()
---C++: return &
---C++: inline
returns Item
is static;
Free(me: in out)
---C++: alias ~
is static;
fields
Addr : Address;
isAllocated : Boolean;
LowR : Integer;
UppR : Integer;
LowC : Integer;
UppC : Integer;
end DoubleTab;

127
src/math/math_DoubleTab.gxx Executable file
View File

@@ -0,0 +1,127 @@
// File math_DoubleTab.gxx
// Lpa, le 7/02/92
#include <math_Memory.hxx>
#include <Standard_OutOfRange.hxx>
#include <Standard_Failure.hxx>
#include <Standard_Integer.hxx>
void math_DoubleTab::Allocate()
{
Standard_Integer RowNumber = UppR - LowR + 1;
Standard_Integer ColNumber = UppC - LowC + 1;
Item** TheAddr = (Item**) Standard::Allocate(RowNumber * sizeof(Item*));
Item* Address;
if(isAllocated)
Address = (Item*) Standard::Allocate(RowNumber * ColNumber * sizeof(Item));
else
Address = (Item*) Addr;
Address -= LowC;
for (Standard_Integer Index = 0; Index < RowNumber; Index++) {
TheAddr[Index] = Address;
Address += ColNumber;
}
TheAddr -= LowR;
Addr = (Standard_Address) TheAddr;
}
math_DoubleTab::math_DoubleTab(const Standard_Integer LowerRow,
const Standard_Integer UpperRow,
const Standard_Integer LowerCol,
const Standard_Integer UpperCol) :
isAllocated(Standard_True),
LowR(LowerRow),
UppR(UpperRow),
LowC(LowerCol),
UppC(UpperCol)
{
Allocate();
}
math_DoubleTab::math_DoubleTab(const Item& Tab,
const Standard_Integer LowerRow,
const Standard_Integer UpperRow,
const Standard_Integer LowerCol,
const Standard_Integer UpperCol) :
Addr((void *) &Tab),
isAllocated(Standard_False),
LowR(LowerRow),
UppR(UpperRow),
LowC(LowerCol),
UppC(UpperCol)
{
Allocate();
}
void math_DoubleTab::Init(const Item& InitValue)
{
for (Standard_Integer i = LowR; i <= UppR; i++) {
for (Standard_Integer j = LowC; j <= UppC; j++) {
((Item**) Addr)[i][j] = InitValue;
}
}
}
math_DoubleTab::math_DoubleTab(const math_DoubleTab& Other) :
isAllocated(Standard_True),
LowR(Other.LowR),
UppR(Other.UppR),
LowC(Other.LowC),
UppC(Other.UppC)
{
Allocate();
Standard_Address target = (Standard_Address) &Value(LowR,LowC);
Standard_Address source = (Standard_Address) &Other.Value(LowR,LowC);
memmove(target,source,
(int)((UppR - LowR + 1) * (UppC - LowC + 1) * sizeof(Item)));
}
void math_DoubleTab::Free()
{
Standard_Integer RowNumber = UppR - LowR + 1;
Standard_Integer ColNumber = UppC - LowC + 1;
// free the data
if(isAllocated) {
Standard_Address it = (Standard_Address)&Value(LowR,LowC);
Standard::Free(it);
}
// free the pointers
Standard_Address it = (Standard_Address)(((Item**)Addr) + LowR);
Standard::Free (it);
Addr = 0;
}
void math_DoubleTab::SetLowerRow(const Standard_Integer LowerRow)
{
Item** TheAddr = (Item**)Addr;
Addr = (Standard_Address) (TheAddr + LowR - LowerRow);
UppR = UppR - LowR + LowerRow;
LowR = LowerRow;
}
void math_DoubleTab::SetLowerCol(const Standard_Integer LowerCol)
{
Item** TheAddr = (Item**) Addr;
for (Standard_Integer Index = LowR; Index <= UppR; Index++) {
TheAddr[Index] = TheAddr[Index] + LowC - LowerCol;
}
UppC = UppC - LowC + LowerCol;
LowC = LowerCol;
}

22
src/math/math_DoubleTab.lxx Executable file
View File

@@ -0,0 +1,22 @@
// File math_DoubleTab.lxx
// Lpa, le 7/02/92
#include <math_Memory.hxx>
#include <Standard_OutOfRange.hxx>
inline Item& math_DoubleTab::Value (const Standard_Integer RowIndex,
const Standard_Integer ColIndex) const
{
return ((Item**)Addr)[RowIndex][ColIndex];
}
inline void math_DoubleTab::Copy(math_DoubleTab& Other)const
{
memmove((void*)(& Other.Value(Other.LowR,Other.LowC)),
(void*) (& Value(LowR,LowC)),
(int)((UppR - LowR + 1) * (UppC - LowC + 1) * sizeof(Item)));
}

View File

@@ -0,0 +1,57 @@
-- File: math_EigenValuesSearcher.cdl
-- Created: Thu Dec 15 17:12:52 2005
-- Author: Julia GERASIMOVA
-- <jgv@clubox>
---Copyright: Matra Datavision 2005
class EigenValuesSearcher from math
---Purpose: This class finds eigen values and vectors of
-- real symmetric tridiagonal matrix
uses
Array1OfReal from TColStd,
HArray1OfReal from TColStd,
HArray2OfReal from TColStd,
Vector from math
raises
NotDone from StdFail
is
Create(Diagonal : Array1OfReal from TColStd;
Subdiagonal : Array1OfReal from TColStd)
returns EigenValuesSearcher
raises NotDone; -- if length(Subdiagonal) != length(Diagonal)-1
IsDone(me)
---Purpose: Returns Standard_True if computation is performed
-- successfully.
returns Boolean from Standard;
Dimension(me)
---Purpose: Returns the dimension of matrix
returns Integer from Standard;
EigenValue(me; Index : Integer from Standard)
---Purpose: Returns the Index_th eigen value of matrix
-- Index must be in [1, Dimension()]
returns Real from Standard;
EigenVector(me; Index : Integer from Standard)
---Purpose: Returns the Index_th eigen vector of matrix
-- Index must be in [1, Dimension()]
returns Vector from math;
fields
myDiagonal : HArray1OfReal from TColStd;
mySubdiagonal : HArray1OfReal from TColStd;
myIsDone : Boolean from Standard;
myN : Integer from Standard;
myEigenValues : HArray1OfReal from TColStd;
myEigenVectors : HArray2OfReal from TColStd;
end EigenValuesSearcher;

View File

@@ -0,0 +1,189 @@
// File: math_EigenValuesSearcher.cxx
// Created: Thu Dec 15 17:58:17 2005
// Author: Julia GERASIMOVA
// <jgv@clubox>
#include <math_EigenValuesSearcher.ixx>
//==========================================================================
//function : pythag
// Computation of sqrt(x*x + y*y).
//==========================================================================
static inline Standard_Real pythag(const Standard_Real x,
const Standard_Real y)
{
return Sqrt(x*x + y*y);
}
math_EigenValuesSearcher::math_EigenValuesSearcher(const TColStd_Array1OfReal& Diagonal,
const TColStd_Array1OfReal& Subdiagonal)
{
myIsDone = Standard_False;
Standard_Integer n = Diagonal.Length();
if (Subdiagonal.Length() != n)
Standard_Failure::Raise("math_EigenValuesSearcher : dimension mismatch");
myDiagonal = new TColStd_HArray1OfReal(1, n);
myDiagonal->ChangeArray1() = Diagonal;
mySubdiagonal = new TColStd_HArray1OfReal(1, n);
mySubdiagonal->ChangeArray1() = Subdiagonal;
myN = n;
myEigenValues = new TColStd_HArray1OfReal(1, n);
myEigenVectors = new TColStd_HArray2OfReal(1, n, 1, n);
Standard_Real* d = new Standard_Real [n+1];
Standard_Real* e = new Standard_Real [n+1];
Standard_Real** z = new Standard_Real* [n+1];
Standard_Integer i, j;
for (i = 1; i <= n; i++)
z[i] = new Standard_Real [n+1];
for (i = 1; i <= n; i++)
d[i] = myDiagonal->Value(i);
for (i = 2; i <= n; i++)
e[i] = mySubdiagonal->Value(i);
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
z[i][j] = (i == j)? 1. : 0.;
Standard_Boolean result;
Standard_Integer m;
Standard_Integer l;
Standard_Integer iter;
//Standard_Integer i;
Standard_Integer k;
Standard_Real s;
Standard_Real r;
Standard_Real p;
Standard_Real g;
Standard_Real f;
Standard_Real dd;
Standard_Real c;
Standard_Real b;
result = Standard_True;
if (n != 1)
{
// Shift e.
for (i = 2; i <= n; i++)
e[i - 1] = e[i];
e[n] = 0.0;
for (l = 1; l <= n; l++) {
iter = 0;
do {
for (m = l; m <= n-1; m++) {
dd = Abs(d[m]) + Abs(d[m + 1]);
if (Abs(e[m]) + dd == dd)
break;
}
if (m != l) {
if (iter++ == 30) {
result = Standard_False;
break; //return result;
}
g = (d[l + 1] - d[l])/(2.*e[l]);
r = pythag(1., g);
if (g < 0)
g = d[m] - d[l] + e[l]/(g - r);
else
g = d[m] - d[l] + e[l]/(g + r);
s = 1.;
c = 1.;
p = 0.;
for (i = m - 1; i >= l; i--) {
f = s*e[i];
b = c*e[i];
r = pythag (f, g);
e[i + 1] = r;
if (r == 0.) {
d[i + 1] -= p;
e[m] = 0.;
break;
}
s = f/r;
c = g/r;
g = d[i + 1] - p;
r = (d[i] - g)*s + 2.0*c*b;
p = s*r;
d[i + 1] = g + p;
g = c*r - b;
for (k = 1; k <= n; k++) {
f = z[k][i + 1];
z[k][i + 1] = s*z[k][i] + c*f;
z[k][i] = c*z[k][i] - s*f;
}
}
if (r == 0 && i >= 1)
continue;
d[l] -= p;
e[l] = g;
e[m] = 0.;
}
}
while (m != l);
if (result == Standard_False)
break;
} //end of for (l = 1; l <= n; l++)
} //end of if (n != 1)
if (result)
{
for (i = 1; i <= n; i++)
myEigenValues->ChangeValue(i) = d[i];
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
myEigenVectors->ChangeValue(i, j) = z[i][j];
}
myIsDone = result;
delete [] d;
delete [] e;
for (i = 1; i <= n; i++)
delete [] z[i];
delete [] z;
}
Standard_Boolean math_EigenValuesSearcher::IsDone() const
{
return myIsDone;
}
Standard_Integer math_EigenValuesSearcher::Dimension() const
{
return myN;
}
Standard_Real math_EigenValuesSearcher::EigenValue(const Standard_Integer Index) const
{
return myEigenValues->Value(Index);
}
math_Vector math_EigenValuesSearcher::EigenVector(const Standard_Integer Index) const
{
math_Vector theVector(1, myN);
Standard_Integer i;
for (i = 1; i <= myN; i++)
theVector(i) = myEigenVectors->Value(i, Index);
return theVector;
}

167
src/math/math_FRPR.cdl Executable file
View File

@@ -0,0 +1,167 @@
-- File: FRPR.cdl
-- Created: Tue May 14 17:01:21 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class FRPR from math
---Purpose:
-- this class implements the Fletcher-Reeves-Polak_Ribiere minimization
-- algorithm of a function of multiple variables.
-- Knowledge of the function's gradient is required.
uses Vector from math, Matrix from math,
MultipleVarFunctionWithGradient from math,
Status from math,
OStream from Standard
raises DimensionError from Standard,
NotDone from StdFail
is
Create(F: in out MultipleVarFunctionWithGradient;
StartingPoint: Vector; Tolerance: Real;
NbIterations: Integer=200; ZEPS: Real=1.0e-12)
---Purpose: Computes FRPR minimization function F from input vector
-- StartingPoint. The solution F = Fi is found when 2.0 *
-- abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1) +
-- ZEPS). The maximum number of iterations allowed is given
-- by NbIterations.
returns FRPR;
Create(F: in out MultipleVarFunctionWithGradient;
Tolerance: Real;
NbIterations: Integer = 200;
ZEPS: Real = 1.0e-12)
---Purpose: Purpose
-- Initializes the computation of the minimum of F.
-- Warning
-- A call to the Perform method must be made after this
-- initialization to compute the minimum of the function.
returns FRPR;
Delete(me:out) is virtual;
---C++: alias "Standard_EXPORT virtual ~math_FRPR(){Delete();}"
Perform(me: in out; F: in out MultipleVarFunctionWithGradient;
StartingPoint: Vector)
---Purpose: Use this method after a call to the initialization constructor
-- to compute the minimum of function F.
-- Warning
-- The initialization constructor must have been called before
-- the Perform method is called
is static;
IsSolutionReached(me: in out; F: in out MultipleVarFunctionWithGradient)
---Purpose:
-- The solution F = Fi is found when :
-- 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1)) + ZEPS.
-- The maximum number of iterations allowed is given by NbIterations.
returns Boolean
is virtual;
IsDone(me)
---Purpose: Returns true if the computations are successful, otherwise returns false.
---C++: inline
returns Boolean
is static;
Location(me)
---Purpose: returns the location vector of the minimum.
-- Exception NotDone is raised if the minimum was not found.
---C++: inline
---C++: return const&
returns Vector
raises NotDone
is static;
Location(me; Loc: out Vector)
---Purpose: outputs the location vector of the minimum in Loc.
-- Exception NotDone is raised if the minimum was not found.
-- Exception DimensionError is raised if the range of Loc is not
-- equal to the range of the StartingPoint.
---C++: inline
raises DimensionError,
NotDone
is static;
Minimum(me)
---Purpose: returns the value of the minimum.
-- Exception NotDone is raised if the minimum was not found.
---C++: inline
returns Real
raises NotDone
is static;
Gradient(me)
---Purpose: returns the gradient vector at the minimum.
-- Exception NotDone is raised if the minimum was not found.
---C++: inline
---C++: return const&
returns Vector
raises NotDone
is static;
Gradient(me; Grad: out Vector)
---Purpose: outputs the gradient vector at the minimum in Grad.
-- Exception NotDone is raised if the minimum was not found.
-- Exception DimensionError is raised if the range of Grad is not
-- equal to the range of the StartingPoint.
---C++: inline
raises DimensionError,
NotDone
is static;
NbIterations(me)
---Purpose: returns the number of iterations really done during the
-- computation of the minimum.
-- Exception NotDone is raised if the minimum was not found.
---C++: inline
returns Integer
raises NotDone
is static;
Dump(me; o: in out OStream)
---Purpose: Prints on the stream o information on the current state
-- of the object.
-- Is used to redefine the operator <<.
is static;
fields
Done: Boolean;
TheLocation: Vector is protected;
TheGradient: Vector is protected;
TheMinimum: Real is protected;
PreviousMinimum: Real is protected;
Iter: Integer;
State: Integer;
XTol: Real is protected;
EPSZ: Real is protected;
TheStatus: Status;
Itermax: Integer;
end FRPR;

237
src/math/math_FRPR.cxx Executable file
View File

@@ -0,0 +1,237 @@
//static const char* sccsid = "@(#)math_FRPR.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
//#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#define No_Standard_DimensionError
//#endif
#include <math_FRPR.ixx>
#include <math_BracketMinimum.hxx>
#include <math_BrentMinimum.hxx>
#include <math_Function.hxx>
#include <math_MultipleVarFunction.hxx>
#include <math_MultipleVarFunctionWithGradient.hxx>
// l'utilisation de math_BrentMinumim pur trouver un minimum dans une direction
// donnee n'est pas du tout optimale. voir peut etre interpolation cubique
// classique et aussi essayer "recherche unidimensionnelle economique"
// PROGRAMMATION MATHEMATIQUE (theorie et algorithmes) tome1 page 82.
class DirFunctionTer : public math_Function {
math_Vector *P0;
math_Vector *Dir;
math_Vector *P;
math_MultipleVarFunction *F;
public :
DirFunctionTer(math_Vector& V1,
math_Vector& V2,
math_Vector& V3,
math_MultipleVarFunction& f);
void Initialize(const math_Vector& p0, const math_Vector& dir);
virtual Standard_Boolean Value(const Standard_Real x, Standard_Real& fval);
};
DirFunctionTer::DirFunctionTer(math_Vector& V1,
math_Vector& V2,
math_Vector& V3,
math_MultipleVarFunction& f) {
P0 = &V1;
Dir = &V2;
P = &V3;
F = &f;
}
void DirFunctionTer::Initialize(const math_Vector& p0,
const math_Vector& dir) {
*P0 = p0;
*Dir = dir;
}
Standard_Boolean DirFunctionTer::Value(const Standard_Real x, Standard_Real& fval) {
*P = *Dir;
P->Multiply(x);
P->Add(*P0);
F->Value(*P, fval);
return Standard_True;
}
static Standard_Boolean MinimizeDirection(math_Vector& P,
math_Vector& Dir,
Standard_Real& Result,
DirFunctionTer& F) {
Standard_Real ax, xx, bx;
F.Initialize(P, Dir);
math_BracketMinimum Bracket(F, 0.0, 1.0);
if(Bracket.IsDone()) {
Bracket.Values(ax, xx, bx);
math_BrentMinimum Sol(F, ax, xx, bx, 1.0e-10, 100);
if(Sol.IsDone()) {
Standard_Real Scale = Sol.Location();
Result = Sol.Minimum();
Dir.Multiply(Scale);
P.Add(Dir);
return Standard_True;
}
}
return Standard_False;
}
void math_FRPR::Perform(math_MultipleVarFunctionWithGradient& F,
const math_Vector& StartingPoint) {
Standard_Boolean Good;
Standard_Integer n = TheLocation.Length();
Standard_Integer j, its;
Standard_Real gg, gam, dgg;
math_Vector g(1, n), h(1, n);
math_Vector Temp1(1, n);
math_Vector Temp2(1, n);
math_Vector Temp3(1, n);
DirFunctionTer F_Dir(Temp1, Temp2, Temp3, F);
TheLocation = StartingPoint;
Good = F.Values(TheLocation, PreviousMinimum, TheGradient);
if(!Good) {
Done = Standard_False;
TheStatus = math_FunctionError;
return;
}
g = -TheGradient;
h = g;
TheGradient = g;
for(its = 1; its <= Itermax; its++) {
Iter = its;
Standard_Boolean IsGood = MinimizeDirection(TheLocation,
TheGradient, TheMinimum, F_Dir);
if(!IsGood) {
Done = Standard_False;
TheStatus = math_DirectionSearchError;
return;
}
if(IsSolutionReached(F)) {
Done = Standard_True;
State = F.GetStateNumber();
TheStatus = math_OK;
return;
}
Good = F.Values(TheLocation, PreviousMinimum, TheGradient);
if(!Good) {
Done = Standard_False;
TheStatus = math_FunctionError;
return;
}
dgg =0.0;
gg = 0.0;
for(j = 1; j<= n; j++) {
gg += g(j)*g(j);
// dgg += TheGradient(j)*TheGradient(j); //for Fletcher-Reeves
dgg += (TheGradient(j)+g(j)) * TheGradient(j); //for Polak-Ribiere
}
if (gg == 0.0) {
//Unlikely. If gradient is exactly 0 then we are already done.
Done = Standard_False;
TheStatus = math_FunctionError;
return;
}
gam = dgg/gg;
g = -TheGradient;
TheGradient = g + gam*h;
h = TheGradient;
}
Done = Standard_False;
TheStatus = math_TooManyIterations;
return;
}
Standard_Boolean math_FRPR::IsSolutionReached(
// math_MultipleVarFunctionWithGradient& F) {
math_MultipleVarFunctionWithGradient& ) {
return (2.0 * fabs(TheMinimum - PreviousMinimum)) <=
XTol * (fabs(TheMinimum) + fabs(PreviousMinimum) + EPSZ);
}
math_FRPR::math_FRPR(math_MultipleVarFunctionWithGradient& F,
const math_Vector& StartingPoint,
const Standard_Real Tolerance,
const Standard_Integer NbIterations,
const Standard_Real ZEPS)
: TheLocation(1, StartingPoint.Length()),
TheGradient(1, StartingPoint.Length()) {
XTol = Tolerance;
EPSZ = ZEPS;
Itermax = NbIterations;
Perform(F, StartingPoint);
}
math_FRPR::math_FRPR(math_MultipleVarFunctionWithGradient& F,
const Standard_Real Tolerance,
const Standard_Integer NbIterations,
const Standard_Real ZEPS)
: TheLocation(1, F.NbVariables()),
TheGradient(1, F.NbVariables()) {
XTol = Tolerance;
EPSZ = ZEPS;
Itermax = NbIterations;
}
void math_FRPR::Delete()
{}
void math_FRPR::Dump(Standard_OStream& o) const {
o << "math_FRPR ";
if(Done) {
o << " Status = Done \n";
o << " Location Vector = "<< TheLocation << "\n";
o << " Minimum value = " << TheMinimum <<"\n";
o << " Number of iterations = " << Iter <<"\n";
}
else {
o << " Status = not Done because " << (Standard_Integer)TheStatus << "\n";
}
}

55
src/math/math_FRPR.lxx Executable file
View File

@@ -0,0 +1,55 @@
// file math_Powell.lxx
#include <StdFail_NotDone.hxx>
#include <math_Vector.hxx>
inline Standard_Boolean math_FRPR::IsDone() const { return Done; }
inline Standard_OStream& operator<<(Standard_OStream& o,
const math_FRPR& Fr)
{
Fr.Dump(o);
return o;
}
inline const math_Vector& math_FRPR::Location() const{
StdFail_NotDone_Raise_if(!Done, " ");
return TheLocation;
}
inline void math_FRPR::Location(math_Vector& Loc) const{
StdFail_NotDone_Raise_if(!Done, " ");
Loc = TheLocation;
}
inline const math_Vector& math_FRPR::Gradient() const{
StdFail_NotDone_Raise_if(!Done, " ");
return TheGradient;
}
inline void math_FRPR::Gradient(math_Vector& Grad) const{
StdFail_NotDone_Raise_if(!Done, " ");
Grad = TheGradient;
}
inline Standard_Real math_FRPR::Minimum() const{
StdFail_NotDone_Raise_if(!Done, " ");
return TheMinimum;
}
inline Standard_Integer math_FRPR::NbIterations() const{
StdFail_NotDone_Raise_if(!Done, " ");
return Iter;
}

48
src/math/math_Function.cdl Executable file
View File

@@ -0,0 +1,48 @@
-- File: Function.cdl
-- Created: Mon May 6 10:54:17 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
deferred class Function from math
---Purpose: This abstract class describes the virtual functions
-- associated with a Function of a single variable.
is
Value(me: in out; X: Real; F: out Real)
---Purpose: Computes the value of the function <F> for a given value of
-- variable <X>.
-- returns True if the computation was done successfully,
-- False otherwise.
returns Boolean
is deferred;
GetStateNumber(me: in out)
---Purpose: returns the state of the function corresponding to the
-- latest call of any methods associated with the function.
-- This function is called by each of the algorithms
-- described later which defined the function Integer
-- Algorithm::StateNumber(). The algorithm has the
-- responsibility to call this function when it has found
-- a solution (i.e. a root or a minimum) and has to maintain
-- the association between the solution found and this
-- StateNumber.
-- Byu default, this method returns 0 (which means for the
-- algorithm: no state has been saved). It is the
-- responsibility of the programmer to decide if he needs
-- to save the current state of the function and to return
-- an Integer that allows retrieval of the state.
returns Integer
is virtual;
end Function;

5
src/math/math_Function.cxx Executable file
View File

@@ -0,0 +1,5 @@
//static const char* sccsid = "@(#)math_Function.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
#include <Standard_Integer.hxx>
#include <math_Function.ixx>
Standard_Integer math_Function::GetStateNumber() { return 0; }

View File

@@ -0,0 +1,136 @@
-- File: FunctionAllRoots.cdl
-- Created: Wed Jul 17 14:35:37 1991
-- Author: Isabelle GRIGNON
-- <isg@topsn3>
---Copyright: Matra Datavision 1991, 1992
class FunctionAllRoots from math
---Purpose: This algorithm uses a sample of the function to find
-- all intervals on which the function is null, and afterwards
-- uses the FunctionRoots algorithm to find the points
-- where the function is null outside the "null intervals".
-- Knowledge of the derivative is required.
uses FunctionSample from math,
FunctionRoots from math,
FunctionWithDerivative from math,
SequenceOfReal from TColStd,
SequenceOfInteger from TColStd,
OStream from Standard
raises OutOfRange from Standard,
NotDone from StdFail,
NumericError from Standard
is
Create(F: in out FunctionWithDerivative from math;
S: FunctionSample from math;
EpsX, EpsF, EpsNul: Real)
---Purpose: The algorithm uses the sample to find intervals on which
-- the function is null. An interval is found if, for at least
-- two consecutive points of the sample, Ui and Ui+1, we get
-- |F(Ui)|<=EpsNul and |F(Ui+1)|<=EpsNul. The real bounds of
-- an interval are computed with the FunctionRoots.
-- algorithm.
-- Between two intervals, the roots of the function F are
-- calculated using the FunctionRoots algorithm.
returns FunctionAllRoots
raises NumericError from Standard;
IsDone(me)
---Purpose: Returns True if the computation has been done successfully.
---C++: inline
returns Boolean
is static;
NbIntervals(me)
---Purpose: Returns the number of intervals on which the function
-- is Null.
-- An exception is raised if IsDone returns False.
---C++: inline
returns Integer
raises NotDone from StdFail
is static;
GetInterval(me; Index: Integer; A,B: out Real)
---Purpose: Returns the interval of parameter of range Index.
-- An exception is raised if IsDone returns False;
-- An exception is raised if Index<=0 or Index >Nbintervals.
---C++: inline
raises NotDone from StdFail, OutOfRange from Standard
is static;
GetIntervalState(me; Index: Integer; IFirst, ILast: out Integer)
---Purpose: returns the State Number associated to the interval Index.
-- An exception is raised if IsDone returns False;
-- An exception is raised if Index<=0 or Index >Nbintervals.
---C++: inline
raises NotDone from StdFail, OutOfRange from Standard
is static;
NbPoints(me)
---Purpose: returns the number of points where the function is Null.
-- An exception is raised if IsDone returns False.
---C++: inline
returns Integer
raises NotDone from StdFail
is static;
GetPoint(me; Index: Integer)
---Purpose: Returns the parameter of the point of range Index.
-- An exception is raised if IsDone returns False;
-- An exception is raised if Index<=0 or Index >NbPoints.
---C++: inline
returns Real
raises NotDone from StdFail, OutOfRange from Standard
is static;
GetPointState(me; Index: Integer)
---Purpose: returns the State Number associated to the point Index.
-- An exception is raised if IsDone returns False;
-- An exception is raised if Index<=0 or Index >Nbintervals.
---C++: inline
returns Integer
raises NotDone from StdFail, OutOfRange from Standard
is static;
Dump(me; o: in out OStream)
---Purpose: Prints on the stream o information on the current state
-- of the object.
is static;
fields
done: Boolean;
pdeb: SequenceOfReal from TColStd;
pfin: SequenceOfReal from TColStd;
piso: SequenceOfReal from TColStd;
ideb: SequenceOfInteger from TColStd;
ifin: SequenceOfInteger from TColStd;
iiso: SequenceOfInteger from TColStd;
end FunctionAllRoots;

View File

@@ -0,0 +1,219 @@
//static const char* sccsid = "@(#)math_FunctionAllRoots.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
//#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#define No_Standard_DimensionError
//#endif
#include <math_FunctionAllRoots.ixx>
#include <Standard_NumericError.hxx>
#include <Standard_OutOfRange.hxx>
#include <math_FunctionRoots.hxx>
#include <math_FunctionWithDerivative.hxx>
#include <math_FunctionSample.hxx>
math_FunctionAllRoots::math_FunctionAllRoots (
math_FunctionWithDerivative& F,
const math_FunctionSample& S,
const Standard_Real EpsX, const Standard_Real EpsF,
const Standard_Real EpsNul) {
done=Standard_False;
Standard_Boolean Nul, PNul, InterNul, Nuld, Nulf;
Standard_Real DebNul,FinNul;
Standard_Integer Indd,Indf;
Standard_Real cst,val,valsav=0,valbid;
Standard_Boolean bid,fini;
Standard_Integer Nbp,i;
Nbp=S.NbPoints();
bid=F.Value(S.GetParameter(1),val);
PNul=Abs(val)<=EpsNul;
if (!PNul) {valsav=val;}
InterNul=Standard_False;
Nuld=Standard_False;
Nulf=Standard_False;
i=2;
fini=(i>Nbp);
while (!fini) {
bid=F.Value(S.GetParameter(i),val);
Nul=Abs(val)<=EpsNul;
if (!Nul) {
valsav=val;
}
if (InterNul && (!Nul)) {
InterNul=Standard_False;
pdeb.Append(DebNul);
ideb.Append(Indd);
if (val>0.0) {
cst=EpsNul;
}
else {
cst=-EpsNul;
}
math_FunctionRoots Res1(F,S.GetParameter(i-1),S.GetParameter(i),10,
EpsX,EpsF,0.0,cst);
Standard_NumericError_Raise_if((!Res1.IsDone()) ||
(Res1.IsAllNull()) ||
(Res1.NbSolutions()==0), " ");
FinNul=Res1.Value(1);
Indf=Res1.StateNumber(1);
cst=-cst;
math_FunctionRoots Res2(F,S.GetParameter(i-1),S.GetParameter(i),10,
EpsX,EpsF,0.0,cst);
Standard_NumericError_Raise_if((!Res2.IsDone()) ||
(Res2.IsAllNull())," ");
//-- || (Res2.NbSolutions()!=0), " "); lbr le 13 mai 87 (!=0 -> ==0)
if (Res2.NbSolutions()!=0) {
if (Res2.Value(1) < FinNul) {
FinNul = Res2.Value(1);
Indf = Res2.StateNumber(1);
}
}
pfin.Append(FinNul);
ifin.Append(Indf);
}
else if ((!InterNul) && PNul && Nul) {
InterNul=Standard_True;
if (i==2) {
DebNul=S.GetParameter(1);
bid = F.Value(DebNul,valbid);
Indd = F.GetStateNumber();
Nuld=Standard_True;
}
else {
if (valsav>0.0) {
cst=EpsNul;
}
else {
cst=-EpsNul;
}
math_FunctionRoots Res1(F,S.GetParameter(i-2),S.GetParameter(i-1),10,
EpsX,EpsF,0.0,cst);
Standard_NumericError_Raise_if((!Res1.IsDone()) ||
(Res1.IsAllNull()) ||
(Res1.NbSolutions()==0), " ");
DebNul=Res1.Value(Res1.NbSolutions());
Indd = Res1.StateNumber(Res1.NbSolutions());
cst=-cst;
math_FunctionRoots Res3(F,S.GetParameter(i-2),S.GetParameter(i-1),10,
EpsX,EpsF,0.0,cst);
Standard_NumericError_Raise_if((!Res3.IsDone()) ||
(Res3.IsAllNull()), " ");
if (Res3.NbSolutions()!=0) {
if (Res3.Value(Res3.NbSolutions()) > DebNul) {
DebNul = Res3.Value(Res3.NbSolutions());
Indd = Res3.StateNumber(Res3.NbSolutions());
}
}
}
}
i=i+1;
PNul=Nul;
fini=(i>Nbp);
}
if (InterNul) { // rajouter l intervalle finissant au dernier pt
pdeb.Append(DebNul);
ideb.Append(Indd);
FinNul = S.GetParameter(Nbp);
bid = F.Value(FinNul,valbid);
Indf = F.GetStateNumber();
pfin.Append(FinNul);
ifin.Append(Indf);
Nulf=Standard_True;
}
if (pdeb.Length()==0) { // Pas d intervalle nul
math_FunctionRoots Res(F,S.GetParameter(1),S.GetParameter(Nbp),Nbp,
EpsX,EpsF,0.0);
Standard_NumericError_Raise_if((!Res.IsDone()) ||
(Res.IsAllNull()), " ");
for (Standard_Integer j=1; j<=Res.NbSolutions(); j++) {
piso.Append(Res.Value(j));
iiso.Append(Res.StateNumber(j));
}
}
else {
Standard_Integer NbpMin = 3;
Standard_Integer Nbrpt;
if (!Nuld) { // Recherche des solutions entre S.GetParameter(1)
// et le debut du 1er intervalle nul
Nbrpt=(Standard_Integer ) IntegerPart(
Abs((pdeb.Value(1)-S.GetParameter(1))/
(S.GetParameter(Nbp)-S.GetParameter(1)))*Nbp);
math_FunctionRoots Res(F,S.GetParameter(1),pdeb.Value(1),
Max(Nbrpt, NbpMin), EpsX,EpsF,0.0);
Standard_NumericError_Raise_if((!Res.IsDone()) ||
(Res.IsAllNull()), " ");
for (Standard_Integer j=1; j<=Res.NbSolutions(); j++) {
piso.Append(Res.Value(j));
iiso.Append(Res.StateNumber(j));
}
}
for (Standard_Integer k=2; k<=pdeb.Length(); k++) {
Nbrpt=(Standard_Integer )
IntegerPart(Abs((pdeb.Value(k)-pfin.Value(k-1))/
(S.GetParameter(Nbp)-S.GetParameter(1)))*Nbp);
math_FunctionRoots Res(F,pfin.Value(k-1),pdeb.Value(k),
Max(Nbrpt, NbpMin), EpsX,EpsF,0.0);
Standard_NumericError_Raise_if((!Res.IsDone()) ||
(Res.IsAllNull()), " ");
for (Standard_Integer j=1; j<=Res.NbSolutions(); j++) {
piso.Append(Res.Value(j));
iiso.Append(Res.StateNumber(j));
}
}
if (!Nulf) { // Recherche des solutions entre la fin du
// dernier intervalle nul et Value(Nbp).
Nbrpt=(Standard_Integer )
IntegerPart(Abs((S.GetParameter(Nbp)-
pfin.Value(pdeb.Length()))/
(S.GetParameter(Nbp)-S.GetParameter(1)))*Nbp);
math_FunctionRoots Res(F,pfin.Value(pdeb.Length()),
S.GetParameter(Nbp), Max(Nbrpt, NbpMin),
EpsX,EpsF,0.0);
Standard_NumericError_Raise_if((!Res.IsDone()) ||
(Res.IsAllNull()), " ");
for (Standard_Integer j=1; j<=Res.NbSolutions(); j++) {
piso.Append(Res.Value(j));
iiso.Append(Res.StateNumber(j));
}
}
}
done=Standard_True;
}
void math_FunctionAllRoots::Dump(Standard_OStream& o) const {
o<< "math_FunctionAllRoots ";
if(done) {
o<< " Status = Done \n";
o << " Number of null intervals = " << pdeb.Length() << endl;
o << " Number of points where the function is null: " << piso.Length() << endl;
}
else {
o<< " Status = not Done \n";
}
}

View File

@@ -0,0 +1,53 @@
// File math_FunctionAllRoots.lxx
#include <StdFail_NotDone.hxx>
#include <TColStd_SequenceOfReal.hxx>
#include <TColStd_SequenceOfInteger.hxx>
inline Standard_Boolean math_FunctionAllRoots::IsDone() const { return done; }
inline Standard_OStream& operator<<(Standard_OStream& o,
const math_FunctionAllRoots& F)
{
F.Dump(o);
return o;
}
inline Standard_Integer math_FunctionAllRoots::NbIntervals () const {
StdFail_NotDone_Raise_if(!done, " ");
return pdeb.Length();
}
inline void math_FunctionAllRoots::GetInterval (const Standard_Integer Index,
Standard_Real& A,
Standard_Real& B) const {
StdFail_NotDone_Raise_if(!done, " ");
A=pdeb.Value(Index);
B=pfin.Value(Index);
}
inline void math_FunctionAllRoots::GetIntervalState (const Standard_Integer Index,
Standard_Integer& IFirst,
Standard_Integer& ILast) const {
StdFail_NotDone_Raise_if(!done, " ");
IFirst=ideb.Value(Index);
ILast=ifin.Value(Index);
}
inline Standard_Integer math_FunctionAllRoots::NbPoints () const {
StdFail_NotDone_Raise_if(!done, " ");
return piso.Length();
}
inline Standard_Real math_FunctionAllRoots::GetPoint (const Standard_Integer Index) const {
StdFail_NotDone_Raise_if(!done, " ");
return piso.Value(Index);
}
inline Standard_Integer math_FunctionAllRoots::GetPointState (const Standard_Integer Index) const {
StdFail_NotDone_Raise_if(!done, " ");
return iiso.Value(Index);
}

116
src/math/math_FunctionRoot.cdl Executable file
View File

@@ -0,0 +1,116 @@
-- File: FunctionRoot.cdl
-- Created: Tue 14 11:02:43 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
--
class FunctionRoot from math
---Purpose:
-- This class implements the computation of a root of a function of
-- a single variable which is near an initial guess using a minimization
-- algorithm.Knowledge of the derivative is required. The
-- algorithm used is the same as in
uses Vector from math, Matrix from math,
FunctionWithDerivative from math,
OStream from Standard
raises NotDone from StdFail
is
Create(F: in out FunctionWithDerivative;
Guess, Tolerance: Real;
NbIterations: Integer = 100)
---Purpose:
-- The Newton-Raphson method is done to find the root of the function F
-- from the initial guess Guess.The tolerance required on
-- the root is given by Tolerance. Iterations are stopped if
-- the expected solution does not stay in the range A..B.
-- The solution is found when abs(Xi - Xi-1) <= Tolerance;
-- The maximum number of iterations allowed is given by NbIterations.
returns FunctionRoot;
Create(F: in out FunctionWithDerivative;
Guess, Tolerance,A,B: Real;
NbIterations: Integer = 100)
---Purpose:
-- The Newton-Raphson method is done to find the root of the function F
-- from the initial guess Guess.
-- The tolerance required on the root is given by Tolerance.
-- Iterations are stopped if the expected solution does not stay in the
-- range A..B
-- The solution is found when abs(Xi - Xi-1) <= Tolerance;
-- The maximum number of iterations allowed is given by NbIterations.
returns FunctionRoot;
IsDone(me)
---Purpose: Returns true if the computations are successful, otherwise returns false.
---C++: inline
returns Boolean
is static;
Root(me)
---Purpose: returns the value of the root.
-- Exception NotDone is raised if the root was not found.
---C++: inline
returns Real
raises NotDone
is static;
Derivative(me)
---Purpose: returns the value of the derivative at the root.
-- Exception NotDone is raised if the root was not found.
---C++: inline
returns Real
raises NotDone
is static;
Value(me)
---Purpose: returns the value of the function at the root.
-- Exception NotDone is raised if the root was not found.
---C++: inline
returns Real
raises NotDone
is static;
NbIterations(me)
---Purpose: returns the number of iterations really done on the
-- computation of the Root.
-- Exception NotDone is raised if the root was not found.
---C++: inline
returns Integer
raises NotDone
is static;
Dump(me; o: in out OStream)
---Purpose: Prints on the stream o information on the current state
-- of the object.
-- Is used to redefine the operator <<.
is static;
fields
Done: Boolean;
TheRoot: Real ;
TheError: Real ;
TheDerivative: Real ;
NbIter: Integer;
end FunctionRoot;

122
src/math/math_FunctionRoot.cxx Executable file
View File

@@ -0,0 +1,122 @@
//static const char* sccsid = "@(#)math_FunctionRoot.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
//#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#define No_Standard_DimensionError
//#endif
#include <Standard_Failure.hxx>
#include <math_FunctionRoot.ixx>
#include <math_FunctionSetRoot.hxx>
#include <math_FunctionSetWithDerivatives.hxx>
#include <math_FunctionWithDerivative.hxx>
class math_MyFunctionSetWithDerivatives : public math_FunctionSetWithDerivatives {
private:
math_FunctionWithDerivative *Ff;
public :
math_MyFunctionSetWithDerivatives (math_FunctionWithDerivative& F );
Standard_Integer NbVariables () const;
Standard_Integer NbEquations () const;
Standard_Boolean Value (const math_Vector& X, math_Vector& F) ;
Standard_Boolean Derivatives (const math_Vector& X, math_Matrix& D) ;
Standard_Boolean Values (const math_Vector& X, math_Vector& F, math_Matrix& D) ;
};
math_MyFunctionSetWithDerivatives::math_MyFunctionSetWithDerivatives
(math_FunctionWithDerivative& F ) {
Ff = &F ;
}
Standard_Integer math_MyFunctionSetWithDerivatives::NbVariables () const {
return 1;
}
Standard_Integer math_MyFunctionSetWithDerivatives::NbEquations () const {
return 1;
}
Standard_Boolean math_MyFunctionSetWithDerivatives::Value (const math_Vector& X, math_Vector& Fs) {
return Ff->Value(X(1),Fs(1));
}
Standard_Boolean math_MyFunctionSetWithDerivatives::Derivatives (const math_Vector& X, math_Matrix& D) {
return Ff->Derivative(X(1),D(1,1));
}
Standard_Boolean math_MyFunctionSetWithDerivatives::Values (const math_Vector& X, math_Vector& F, math_Matrix& D) {
return Ff->Values(X(1),F(1),D(1,1));
}
math_FunctionRoot::math_FunctionRoot(math_FunctionWithDerivative& F,
const Standard_Real Guess,
const Standard_Real Tolerance,
const Standard_Integer NbIterations ){
Standard_Boolean Ok;
math_Vector V(1,1), Tol(1,1);
math_MyFunctionSetWithDerivatives Ff(F);
V(1)=Guess;
Tol(1) = Tolerance;
math_FunctionSetRoot Sol(Ff,V,Tol,NbIterations);
Done = Sol.IsDone();
if (Done) {
#ifdef DEB
Standard_Integer Ier=F.GetStateNumber();
#else
F.GetStateNumber();
#endif
TheRoot = Sol.Root()(1);
TheDerivative = Sol.Derivative()(1,1);
Ok = F.Value(TheRoot,TheError);
NbIter = Sol.NbIterations();
}
}
math_FunctionRoot::math_FunctionRoot(math_FunctionWithDerivative& F,
const Standard_Real Guess,
const Standard_Real Tolerance,
const Standard_Real A,
const Standard_Real B,
const Standard_Integer NbIterations ){
Standard_Boolean Ok;
math_Vector V(1,1),Aa(1,1),Bb(1,1), Tol(1,1);
math_MyFunctionSetWithDerivatives Ff(F);
V(1)=Guess;
Tol(1) = Tolerance;
Aa(1)=A;
Bb(1)=B;
math_FunctionSetRoot Sol(Ff,V,Tol,Aa,Bb,NbIterations);
Done = Sol.IsDone();
if (Done) {
#ifdef DEB
Standard_Integer Ier =F.GetStateNumber();
#else
F.GetStateNumber();
#endif
TheRoot = Sol.Root()(1);
TheDerivative = Sol.Derivative()(1,1);
Ok = F.Value(TheRoot,TheError);
NbIter = Sol.NbIterations();
}
}
void math_FunctionRoot::Dump(Standard_OStream& o) const {
o<< "math_FunctionRoot ";
if(Done) {
o<< " Status = Done \n";
o << " Number of iterations = " << NbIter << endl;
o << " The Root is: " << TheRoot << endl;
o << "The value at the root is: " << TheError << endl;
}
else {
o<< " Status = not Done \n";
}
}

36
src/math/math_FunctionRoot.lxx Executable file
View File

@@ -0,0 +1,36 @@
// File math_FunctionRoot.lxx
#include <StdFail_NotDone.hxx>
inline Standard_Boolean math_FunctionRoot::IsDone() const { return Done; }
inline Standard_OStream& operator<<(Standard_OStream& o,
const math_FunctionRoot& F)
{
F.Dump(o);
return o;
}
inline Standard_Real math_FunctionRoot::Root () const {
StdFail_NotDone_Raise_if(!Done, " ");
return TheRoot;
}
inline Standard_Real math_FunctionRoot::Derivative () const {
StdFail_NotDone_Raise_if(!Done, " ");
return TheDerivative;
}
inline Standard_Real math_FunctionRoot::Value () const {
StdFail_NotDone_Raise_if(!Done, " ");
return TheError;
}
inline Standard_Integer math_FunctionRoot::NbIterations () const {
StdFail_NotDone_Raise_if(!Done, " ");
return NbIter;
}

101
src/math/math_FunctionRoots.cdl Executable file
View File

@@ -0,0 +1,101 @@
-- File: FunctionRoots.cdl
-- Created: Mon May 13 17:39:12 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class FunctionRoots from math
---Purpose:
-- This class implements an algorithm which finds all the real roots of
-- a function with derivative within a given range.
-- Knowledge of the derivative is required.
uses FunctionWithDerivative from math,
SequenceOfReal from TColStd,
SequenceOfInteger from TColStd,
OStream from Standard
raises RangeError from Standard,
NotDone from StdFail
is
Create(F: in out FunctionWithDerivative; A, B: Real;
NbSample: Integer; EpsX, EpsF, EpsNull, K : Real= 0.0)
---Purpose: Calculates all the real roots of a function F-K within the range
-- A..B. whithout conditions on A and B
-- A solution X is found when
-- abs(Xi - Xi-1) <= Epsx and abs(F(Xi)-K) <= EpsF.
-- The function is considered as null between A and B if
-- abs(F-K) <= EpsNull within this range.
returns FunctionRoots;
IsDone(me)
---Purpose: Returns true if the computations are successful, otherwise returns false.
---C++: inline
returns Boolean
is static;
IsAllNull(me)
---Purpose:
-- returns true if the function is considered as null between A and B.
-- Exceptions
-- StdFail_NotDone if the algorithm fails (and IsDone returns false).
---C++: inline
returns Boolean
raises NotDone
is static;
NbSolutions(me)
---Purpose: Returns the number of solutions found.
-- Exceptions
-- StdFail_NotDone if the algorithm fails (and IsDone returns false).
---C++: inline
returns Integer
raises NotDone
is static;
Value(me; Nieme: in Integer)
---Purpose: Returns the Nth value of the root of function F.
-- Exceptions
-- StdFail_NotDone if the algorithm fails (and IsDone returns false).
---C++: inline
returns Real
raises NotDone, RangeError
is static;
StateNumber(me; Nieme: in Integer)
---Purpose:
-- returns the StateNumber of the Nieme root.
-- Exception RangeError is raised if Nieme is < 1
-- or Nieme > NbSolutions.
---C++: inline
returns Integer
raises NotDone
is static;
Dump(me; o: in out OStream)
---Purpose: Prints on the stream o information on the current state
-- of the object.
is static;
fields
Done: Boolean;
AllNull: Boolean;
Sol: SequenceOfReal from TColStd;
NbStateSol: SequenceOfInteger from TColStd;
end FunctionRoots;

1020
src/math/math_FunctionRoots.cxx Executable file

File diff suppressed because it is too large Load Diff

43
src/math/math_FunctionRoots.lxx Executable file
View File

@@ -0,0 +1,43 @@
// file math_FunctionRoots.lxx
#include <StdFail_NotDone.hxx>
#include <TColStd_SequenceOfReal.hxx>
#include <TColStd_SequenceOfInteger.hxx>
inline Standard_Boolean math_FunctionRoots::IsDone() const { return Done; }
inline Standard_OStream& operator<<(Standard_OStream& o,
const math_FunctionRoots& F)
{
F.Dump(o);
return o;
}
inline Standard_Boolean math_FunctionRoots::IsAllNull() const{
StdFail_NotDone_Raise_if(!Done, " ");
return AllNull;
}
inline Standard_Integer math_FunctionRoots::NbSolutions() const{
StdFail_NotDone_Raise_if(!Done, " ");
return Sol.Length();
}
inline Standard_Real math_FunctionRoots::Value(const Standard_Integer Nieme) const{
StdFail_NotDone_Raise_if(!Done, " ");
return Sol.Value(Nieme);
}
inline Standard_Integer math_FunctionRoots::StateNumber(const Standard_Integer Nieme) const{
StdFail_NotDone_Raise_if(!Done, " ");
return NbStateSol.Value(Nieme);
}

View File

@@ -0,0 +1,55 @@
-- File: FunctionSample.cdl
-- Created: Wed Jul 17 14:35:02 1991
-- Author: Isabelle GRIGNON
-- <isg@topsn3>
---Copyright: Matra Datavision 1991
class FunctionSample from math
---Purpose: This class gives a default sample (constant difference
-- of parameter) for a function defined between
-- two bound A,B.
raises OutOfRange from Standard
is
Create(A,B: Real; N: Integer)
returns FunctionSample from math;
Bounds(me; A,B: out Real) is virtual;
---Purpose: Returns the bounds of parameters.
NbPoints(me)
---Purpose: Returns the number of sample points.
returns Integer
is static;
GetParameter(me; Index: Integer)
---Purpose: Returns the value of parameter of the point of
-- range Index : A + ((Index-1)/(NbPoints-1))*B.
-- An exception is raised if Index<=0 or Index>NbPoints.
returns Real
raises OutOfRange
is virtual;
fields
a: Real;
b: Real;
n: Integer;
end FunctionSample;

View File

@@ -0,0 +1,38 @@
//static const char* sccsid = "@(#)math_FunctionSample.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
//#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#define No_Standard_DimensionError
//#endif
#include <math_FunctionSample.ixx>
#include <Standard_OutOfRange.hxx>
math_FunctionSample::math_FunctionSample (const Standard_Real A,
const Standard_Real B,
const Standard_Integer N):
a(A),b(B),n(N)
{
}
void math_FunctionSample::Bounds (Standard_Real& A, Standard_Real& B) const {
A=a;
B=b;
}
Standard_Integer math_FunctionSample::NbPoints () const {
return n;
}
Standard_Real math_FunctionSample::GetParameter (const Standard_Integer Index) const {
Standard_OutOfRange_Raise_if((Index <= 0)||(Index > n), " ");
return ((n-Index)*a+(Index-1)*b)/(n-1);
}

65
src/math/math_FunctionSet.cdl Executable file
View File

@@ -0,0 +1,65 @@
-- File: FunctionSet.cdl
-- Created: Mon May 13 15:21:04 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
--Copyright: Matra Datavision 1991
deferred class FunctionSet from math
---Purpose:
-- This abstract class describes the virtual functions associated to
-- a set on N Functions of M independant variables.
uses Vector from math
is
Delete(me:out) is virtual;
---C++: alias "Standard_EXPORT virtual ~math_FunctionSet(){Delete();}"
NbVariables(me)
---Purpose: Returns the number of variables of the function.
returns Integer
is deferred;
NbEquations(me)
---Purpose: Returns the number of equations of the function.
returns Integer
is deferred;
Value(me: in out; X: Vector; F: out Vector)
---Purpose: Computes the values <F> of the functions for the
-- variable <X>.
-- returns True if the computation was done successfully,
-- False otherwise.
returns Boolean
is deferred;
GetStateNumber(me: in out)
---Purpose: Returns the state of the function corresponding to the
-- latestcall of any methods associated with the function.
-- This function is called by each of the algorithms
-- described later which define the function Integer
-- Algorithm::StateNumber(). The algorithm has the
-- responsibility to call this function when it has found
-- a solution (i.e. a root or a minimum) and has to maintain
-- the association between the solution found and this
-- StateNumber.
-- Byu default, this method returns 0 (which means for the
-- algorithm: no state has been saved). It is the
-- responsibility of the programmer to decide if he needs
-- to save the current state of the function and to return
-- an Integer that allows retrieval of the state.
returns Integer
is virtual;
end FunctionSet;

8
src/math/math_FunctionSet.cxx Executable file
View File

@@ -0,0 +1,8 @@
//static const char* sccsid = "@(#)math_FunctionSet.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
#include <Standard_Integer.hxx>
#include <math_FunctionSet.ixx>
Standard_Integer math_FunctionSet::GetStateNumber() { return 0; }
void math_FunctionSet::Delete()
{}

249
src/math/math_FunctionSetRoot.cdl Executable file
View File

@@ -0,0 +1,249 @@
-- File: FunctionSetRoot.cdl
-- Created: Tue May 14 14:32:21 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class FunctionSetRoot from math
---Purpose: The math_FunctionSetRoot class calculates the root
-- of a set of N functions of M variables (N<M, N=M or N>M). Knowing
-- an initial guess of the solution and using a minimization algorithm, a search
-- is made in the Newton direction and then in the Gradient direction if there
-- is no success in the Newton direction. This algorithm can also be
-- used for functions minimization. Knowledge of all the partial
-- derivatives (the Jacobian) is required.
uses Vector from math,
Matrix from math,
IntegerVector from math,
FunctionSetWithDerivatives from math,
OStream from Standard
raises NotDone from StdFail,
DimensionError from Standard
is
Create(F: in out FunctionSetWithDerivatives;
Tolerance : Vector;
NbIterations: Integer = 100)
---Purpose: is used in a sub-class to initialize correctly all the fields
-- of this class.
-- The range (1, F.NbVariables()) must be especially
-- respected for all vectors and matrix declarations.
returns FunctionSetRoot from math;
Create(F: in out FunctionSetWithDerivatives;
NbIterations: Integer = 100)
---Purpose: is used in a sub-class to initialize correctly all the fields
-- of this class.
-- The range (1, F.NbVariables()) must be especially
-- respected for all vectors and matrix declarations.
-- The method SetTolerance must be called after this
-- constructor.
returns FunctionSetRoot from math;
Create(F: in out FunctionSetWithDerivatives; StartingPoint: Vector;
Tolerance: Vector; NbIterations: Integer = 100)
---Purpose: is used to improve the root of the function F
-- from the initial guess StartingPoint.
-- The maximum number of iterations allowed is given by
-- NbIterations.
-- In this case, the solution is found when:
-- abs(Xi - Xi-1)(j) <= Tolerance(j) for all unknowns.
returns FunctionSetRoot from math;
Create(F: in out FunctionSetWithDerivatives; StartingPoint: Vector;
Tolerance: Vector; infBound, supBound: Vector;
NbIterations: Integer = 100)
---Purpose: is used to improve the root of the function F
-- from the initial guess StartingPoint.
-- The maximum number of iterations allowed is given
-- by NbIterations.
-- In this case, the solution is found when:
-- abs(Xi - Xi-1) <= Tolerance for all unknowns.
returns FunctionSetRoot from math;
Delete(me:out) is virtual;
---C++: alias "Standard_EXPORT virtual ~math_FunctionSetRoot(){Delete();}"
SetTolerance(me: in out; Tolerance: Vector)
---Purpose: Initializes the tolerance values.
is static;
Perform(me: in out; F: in out FunctionSetWithDerivatives;
StartingPoint: Vector;
infBound, supBound: Vector)
---Purpose: Improves the root of function F from the initial guess
-- StartingPoint. infBound and supBound may be given to constrain the solution.
-- Warning
-- This method is called when computation of the solution is
-- not performed by the constructors.
is static;
IsSolutionReached(me: in out; F: in out FunctionSetWithDerivatives)
---Purpose: This routine is called at the end of each iteration
-- to check if the solution was found. It can be redefined
-- in a sub-class to implement a specific test to stop the
-- iterations.
-- In this case, the solution is found when:
-- abs(Xi - Xi-1) <= Tolerance for all unknowns.
returns Boolean is virtual;
IsDone(me)
---Purpose:
-- Returns true if the computations are successful, otherwise returns false.
---C++: inline
returns Boolean
is static;
NbIterations(me)
---Purpose: Returns the number of iterations really done
-- during the computation of the root.
-- Exception NotDone is raised if the root was not found.
---C++: inline
returns Integer
raises NotDone
is static;
StateNumber(me)
---Purpose: returns the stateNumber (as returned by
-- F.GetStateNumber()) associated to the root found.
---C++: inline
returns Integer
raises NotDone
is static;
Root(me)
---Purpose: Returns the value of the root of function F.
-- Exception NotDone is raised if the root was not found.
---C++: inline
---C++: return const&
returns Vector
raises NotDone,
DimensionError
is static;
Root(me; Root: out Vector)
---Purpose: Outputs the root vector in Root.
-- Exception NotDone is raised if the root was not found.
-- Exception DimensionError is raised if the range of Root
-- is not equal to the range of the StartingPoint.
raises NotDone from StdFail
is static;
Derivative(me)
---Purpose: Returns the matrix value of the derivative at the root.
-- Exception NotDone is raised if the root was not found.
---C++: inline
---C++: return const&
returns Matrix
raises NotDone
is static;
Derivative(me; Der: out Matrix)
---Purpose: outputs the matrix value of the derivative
-- at the root in Der.
-- Exception NotDone is raised if the root was not found.
-- Exception DimensionError is raised if the column range
-- of <Der> is not equal to the range of the startingPoint.
---C++: inline
raises NotDone,
DimensionError
is static;
FunctionSetErrors(me)
---Purpose: returns the vector value of the error done
-- on the functions at the root.
-- Exception NotDone is raised if the root was not found.
---C++: inline
---C++: return const&
returns Vector
raises NotDone
is static;
FunctionSetErrors(me; Err: out Vector)
---Purpose: outputs the vector value of the error done
-- on the functions at the root in Err.
-- Exception NotDone is raised if the root was not found.
-- Exception DimensionError is raised if the range of Err
-- is not equal to the range of the StartingPoint.
raises NotDone,
DimensionError
is static;
Dump(me; o: in out OStream)
---Purpose: Prints on the stream o information on the current state
-- of the object.
-- Is used to redefine the operator <<.
is static;
fields
Done : Boolean;
Delta : Vector is protected;
Sol : Vector is protected;
DF : Matrix is protected;
Kount : Integer;
State : Integer;
Tol : Vector is protected;
Itermax : Integer;
-- working tables
InfBound : Vector;
SupBound : Vector;
SolSave : Vector;
GH : Vector;
DH : Vector;
DHSave : Vector;
FF : Vector;
PreviousSolution : Vector;
Save : Vector;
Constraints : IntegerVector;
Temp1 : Vector;
Temp2 : Vector;
Temp3 : Vector;
Temp4 : Vector;
end FunctionSetRoot;

1087
src/math/math_FunctionSetRoot.cxx Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,51 @@
// File math_FunctionSetRoot.lxx
#include <StdFail_NotDone.hxx>
#include <Standard_DimensionError.hxx>
inline Standard_Boolean math_FunctionSetRoot::IsDone() const { return Done; }
inline Standard_OStream& operator<<(Standard_OStream& o,
const math_FunctionSetRoot& F)
{
F.Dump(o);
return o;
}
inline const math_Vector& math_FunctionSetRoot::Root() const{
StdFail_NotDone_Raise_if(!Done, " ");
return Sol;
}
inline const math_Vector& math_FunctionSetRoot::FunctionSetErrors() const{
StdFail_NotDone_Raise_if(!Done, " ");
return Delta;
}
inline const math_Matrix& math_FunctionSetRoot::Derivative() const{
StdFail_NotDone_Raise_if(!Done, " ");
return DF;
}
inline void math_FunctionSetRoot::Derivative(math_Matrix& Der) const{
StdFail_NotDone_Raise_if(!Done, " ");
Standard_DimensionError_Raise_if(Der.ColNumber() != Sol.Length(), " ");
Der = DF;
}
inline Standard_Integer math_FunctionSetRoot::StateNumber() const{
StdFail_NotDone_Raise_if(!Done, " ");
return State;
}
inline Standard_Integer math_FunctionSetRoot::NbIterations() const{
StdFail_NotDone_Raise_if(!Done, " ");
return Kount;
}

View File

@@ -0,0 +1,64 @@
-- File: FunctionSetWithDerivatives.cdl
-- Created: Mon May 13 15:33:43 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
deferred class FunctionSetWithDerivatives from math
inherits FunctionSet
---Purpose: This abstract class describes the virtual functions associated
-- with a set of N Functions each of M independant variables.
uses Vector from math, Matrix from math
is
NbVariables(me)
---Purpose: Returns the number of variables of the function.
returns Integer
is deferred;
NbEquations(me)
---Purpose: Returns the number of equations of the function.
returns Integer
is deferred;
Value(me: in out; X: Vector; F: out Vector)
---Purpose: Computes the values <F> of the Functions for the
-- variable <X>.
-- Returns True if the computation was done successfully,
-- False otherwise.
returns Boolean
is deferred;
Derivatives(me: in out; X: Vector; D: out Matrix)
---Purpose: Returns the values <D> of the derivatives for the
-- variable <X>.
-- Returns True if the computation was done successfully,
-- False otherwise.
returns Boolean
is deferred;
Values(me: in out; X: Vector; F: out Vector; D: out Matrix)
---Purpose: returns the values <F> of the functions and the derivatives
-- <D> for the variable <X>.
-- Returns True if the computation was done successfully,
-- False otherwise.
returns Boolean
is deferred;
end FunctionSetWithDerivatives;

View File

@@ -0,0 +1,2 @@
//static const char* sccsid = "@(#)math_FunctionSetWithDerivatives.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
#include <math_FunctionSetWithDerivatives.ixx>

View File

@@ -0,0 +1,48 @@
-- File: FunctionWithDerivative.cdl
-- Created: Mon May 13 14:00:19 1991
-- Author: Laurent Painnot
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
deferred class FunctionWithDerivative from math
---Purpose:
-- This abstract class describes the virtual functions associated with
-- a function of a single variable for which the first derivative is
-- available.
inherits Function
is
Delete(me:out) is virtual;
---C++: alias "Standard_EXPORT virtual ~math_FunctionWithDerivative(){Delete();}"
Value(me: in out; X: Real; F: out Real)
---Purpose: Computes the value <F>of the function for the variable <X>.
-- Returns True if the calculation were successfully done,
-- False otherwise.
returns Boolean
is deferred;
Derivative(me: in out; X: Real; D: out Real)
---Purpose: Computes the derivative <D> of the function
-- for the variable <X>.
-- Returns True if the calculation were successfully done,
-- False otherwise.
returns Boolean
is deferred;
Values(me: in out; X: Real; F, D: out Real)
---Purpose: Computes the value <F> and the derivative <D> of the
-- function for the variable <X>.
-- Returns True if the calculation were successfully done,
-- False otherwise.
returns Boolean
is deferred;
end FunctionWithDerivative;

View File

@@ -0,0 +1,5 @@
//static const char* sccsid = "@(#)math_FunctionWithDerivative.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
#include <math_FunctionWithDerivative.ixx>
void math_FunctionWithDerivative::Delete()
{}

120
src/math/math_Gauss.cdl Executable file
View File

@@ -0,0 +1,120 @@
-- File: Gauss.cdl
-- Created: Mon May 13 15:45:42 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class Gauss from math
---Purpose:
-- This class implements the Gauss LU decomposition (Crout algorithm)
-- with partial pivoting (rows interchange) of a square matrix and
-- the different possible derived calculation :
-- - solution of a set of linear equations.
-- - inverse of a matrix.
-- - determinant of a matrix.
uses Vector from math,
IntegerVector from math,
Matrix from math,
OStream from Standard
raises NotSquare from math,
DimensionError from Standard,
NotDone from StdFail
is
Create(A: Matrix; MinPivot: Real = 1.0e-20)
---Purpose:
-- Given an input n X n matrix A this constructor performs its LU
-- decomposition with partial pivoting (interchange of rows).
-- This LU decomposition is stored internally and may be used to
-- do subsequent calculation.
-- If the largest pivot found is less than MinPivot the matrix A is
-- considered as singular.
-- Exception NotSquare is raised if A is not a square matrix.
returns Gauss
raises NotSquare;
IsDone(me)
---Purpose: Returns true if the computations are successful, otherwise returns false
---C++: inline
returns Boolean
is static;
Solve(me; B: Vector; X : out Vector)
---Purpose:
-- Given the input Vector B this routine returns the solution X of the set
-- of linear equations A . X = B.
-- Exception NotDone is raised if the decomposition of A was not done
-- successfully.
-- Exception DimensionError is raised if the range of B is not
-- equal to the number of rows of A.
raises NotDone,
DimensionError
is static;
Solve(me; B: in out Vector)
---Purpose:
-- Given the input Vector B this routine solves the set of linear
-- equations A . X = B. B is replaced by the vector solution X.
-- Exception NotDone is raised if the decomposition of A was not done
-- successfully.
-- Exception DimensionError is raised if the range of B is not
-- equal to the number of rows of A.
raises DimensionError
is static;
Determinant(me)
---Purpose:
-- This routine returns the value of the determinant of the previously LU
-- decomposed matrix A.
-- Exception NotDone may be raised if the decomposition of A was not done
-- successfully, zero is returned if the matrix A was considered as singular.
returns Real
raises NotDone
is static;
Invert(me; Inv: out Matrix)
---Purpose:
-- This routine outputs Inv the inverse of the previously LU decomposed
-- matrix A.
-- Exception DimensionError is raised if the ranges of B are not
-- equal to the ranges of A.
raises DimensionError
is static;
Dump(me; o: in out OStream)
---Purpose: Prints on the stream o information on the current state
-- of the object.
-- Is used to redefine the operator <<.
is static;
fields
Done: Boolean;
Singular: Boolean is protected;
LU: Matrix is protected;
Index: IntegerVector is protected;
D: Real is protected;
end Gauss;

109
src/math/math_Gauss.cxx Executable file
View File

@@ -0,0 +1,109 @@
//static const char* sccsid = "@(#)math_Gauss.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
//#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#define No_Standard_DimensionError
//#endif
#include <math_Gauss.ixx>
#include <math_Recipes.hxx>
#include <math_NotSquare.hxx>
#include <StdFail_NotDone.hxx>
#include <Standard_DimensionError.hxx>
#include <Standard_NotImplemented.hxx>
math_Gauss::math_Gauss(const math_Matrix& A,
const Standard_Real MinPivot)
: LU (1, A.RowNumber(), 1, A.ColNumber()),
Index(1, A.RowNumber()) {
math_NotSquare_Raise_if(A.RowNumber() != A.ColNumber(), " ");
LU = A;
Standard_Integer Error = LU_Decompose(LU,
Index,
D,
MinPivot);
if(!Error) {
Done = Standard_True;
}
else {
Done = Standard_False;
}
}
void math_Gauss::Solve(const math_Vector& B, math_Vector& X) const{
StdFail_NotDone_Raise_if(!Done, " ");
X = B;
LU_Solve(LU,
Index,
X);
}
void math_Gauss::Solve (math_Vector& X) const{
StdFail_NotDone_Raise_if(!Done, " ");
if(X.Length() != LU.RowNumber()) {
Standard_DimensionError::Raise();
}
LU_Solve(LU,
Index,
X);
}
Standard_Real math_Gauss::Determinant() const{
StdFail_NotDone_Raise_if(!Done, " ");
Standard_Real Result = D;
for(Standard_Integer J = 1; J <= LU.UpperRow(); J++) {
Result *= LU(J,J);
}
return Result;
}
void math_Gauss::Invert(math_Matrix& Inv) const{
StdFail_NotDone_Raise_if(!Done, " ");
Standard_DimensionError_Raise_if((Inv.RowNumber() != LU.RowNumber()) ||
(Inv.ColNumber() != LU.ColNumber()),
" ");
Standard_Integer LowerRow = Inv.LowerRow();
Standard_Integer LowerCol = Inv.LowerCol();
math_Vector Column(1, LU.UpperRow());
Standard_Integer I, J;
for(J = 1; J <= LU.UpperRow(); J++) {
for(I = 1; I <= LU.UpperRow(); I++) {
Column(I) = 0.0;
}
Column(J) = 1.0;
LU_Solve(LU, Index, Column);
for(I = 1; I <= LU.RowNumber(); I++) {
Inv(I+LowerRow-1,J+LowerCol-1) = Column(I);
}
}
}
void math_Gauss::Dump(Standard_OStream& o) const {
o << "math_Gauss ";
if(Done) {
o<< " Status = Done \n";
o << " Determinant of A = " << D << endl;
}
else {
o << " Status = not Done \n";
}
}

11
src/math/math_Gauss.lxx Executable file
View File

@@ -0,0 +1,11 @@
// math_Gauss.lxx
// lpa, le 28/01/92
inline Standard_Boolean math_Gauss::IsDone() const { return Done; }
inline Standard_OStream& operator<<(Standard_OStream& o, const math_Gauss& mG)
{
mG.Dump(o);
return o;
}

View File

@@ -0,0 +1,79 @@
-- File: GaussLeastSquare.cdl
-- Created: Mon May 13 16:24:37 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class GaussLeastSquare from math
---Purpose:
-- This class implements the least square solution of a set of
-- n linear equations of m unknowns (n >= m) using the gauss LU
-- decomposition algorithm.
-- This algorithm is more likely subject to numerical instability
-- than math_SVD.
uses Matrix from math,
Vector from math,
IntegerVector from math,
OStream from Standard
raises NotDone from StdFail,
DimensionError from Standard
is
Create(A: Matrix; MinPivot: Real = 1.0e-20)
---Purpose: Given an input n X m matrix A with n >= m this constructor
-- performs the LU decomposition with partial pivoting
-- (interchange of rows) of the matrix AA = A.Transposed() * A;
-- This LU decomposition is stored internally and may be used
-- to do subsequent calculation.
-- If the largest pivot found is less than MinPivot the matrix <A>
-- is considered as singular.
returns GaussLeastSquare;
IsDone(me)
---Purpose: Returns true if the computations are successful, otherwise returns false.e
---C++: inline
returns Boolean
is static;
Solve(me; B: in Vector; X: out Vector)
---Purpose: Given the input Vector <B> this routine solves the set
-- of linear equations A . X = B.
-- Exception NotDone is raised if the decomposition of A was
-- not done successfully.
-- Exception DimensionError is raised if the range of B Inv is
-- not equal to the rowrange of A.
-- Exception DimensionError is raised if the range of X Inv is
-- not equal to the colrange of A.
raises NotDone,
DimensionError
is static;
Dump(me; o: in out OStream)
---Purpose: Prints on the stream o information on the current state
-- of the object.
-- Is used to redefine the operator <<.
is static;
fields
Done: Boolean;
Singular: Boolean is protected;
LU: Matrix is protected;
A2 : Matrix is protected;
Index: IntegerVector is protected;
D: Real is protected;
end GaussLeastSquare;

View File

@@ -0,0 +1,55 @@
//static const char* sccsid = "@(#)math_GaussLeastSquare.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
//#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#define No_Standard_DimensionError
//#endif
#include <math_GaussLeastSquare.ixx>
#include <math_Recipes.hxx>
#include <StdFail_NotDone.hxx>
#include <Standard_DimensionError.hxx>
math_GaussLeastSquare::math_GaussLeastSquare (const math_Matrix& A,
const Standard_Real MinPivot) :
LU(1, A.ColNumber(),
1, A.ColNumber()),
A2(1, A.ColNumber(),
1, A.RowNumber()),
Index(1, A.ColNumber()) {
A2 = A.Transposed();
LU.Multiply(A2, A);
Standard_Integer Error = LU_Decompose(LU, Index, D, MinPivot);
Done = (!Error) ? Standard_True : Standard_False;
}
void math_GaussLeastSquare::Solve(const math_Vector& B, math_Vector& X) const{
StdFail_NotDone_Raise_if(!Done, " ");
Standard_DimensionError_Raise_if((B.Length() != A2.ColNumber()) ||
(X.Length() != A2.RowNumber()), " ");
X.Multiply(A2, B);
LU_Solve(LU, Index, X);
return;
}
void math_GaussLeastSquare::Dump(Standard_OStream& o) const {
o <<"math_GaussLeastSquare ";
if (Done) {
o << " Status = Done \n";
}
else {
o << "Status = not Done \n";
}
}

View File

@@ -0,0 +1,12 @@
// File math_GaussLeastSquare.lxx
inline Standard_Boolean math_GaussLeastSquare::IsDone() const { return Done; }
inline Standard_OStream& operator<<(Standard_OStream& o,
const math_GaussLeastSquare& G)
{
G.Dump(o);
return o;
}

View File

@@ -0,0 +1,62 @@
-- File: GaussMultipleIntegration.cdl
-- Created: Tue May 14 18:22:12 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class GaussMultipleIntegration from math
---Purpose:
-- This class implements the integration of a function of multiple
-- variables between the parameter bounds Lower[a..b] and Upper[a..b].
-- Warning: Each element of Order must be inferior or equal to 61.
uses Vector from math,
IntegerVector from math,
MultipleVarFunction from math,
OStream from Standard
raises NotDone from StdFail
is
Create(F: in out MultipleVarFunction; Lower, Upper: Vector;
Order: IntegerVector)
---Purpose:
-- The Gauss-Legendre integration with Order = points of
-- integration for each unknow, is done on the function F
-- between the bounds Lower and Upper.
returns GaussMultipleIntegration;
IsDone(me)
---Purpose: returns True if all has been correctly done.
---C++: inline
returns Boolean
is static;
Value(me)
---Purpose: returns the value of the integral.
---C++: inline
returns Real
raises NotDone
is static;
Dump(me; o: in out OStream)
---Purpose: Prints information on the current state of the object.
is static;
fields
Val: Real;
Done: Boolean;
end GaussMultipleIntegration;

View File

@@ -0,0 +1,202 @@
//static const char* sccsid = "@(#)math_GaussMultipleIntegration.cxx 3.3 95/01/25"; // Do not delete this line. Used by sccs.
// File math_GaussMultipleIntegration.cxx
/*
Ce programme permet le calcul de l'integrale nieme d'une fonction. La
resolution peut etre vue comme l'integrale de l'integrale de ....(n fois), ce
qui necessite l'emploi de fonction recursive.
Une integrale simple de Gauss est la somme de la fonction donnee sur les points
de Gauss affectee du poids de Gauss correspondant.
I = somme(F(GaussPt) * GaussW) sur i = 1 jusqu'a l'ordre d'integration.
Une integrale multiple est une somme recursive sur toutes les variables.
Tout le calcul est effectue dans la methode recursive_iteration appelee n fois.
(n = nombre de variables)
Cette methode fait une sommation sur toutes les variables, sur tous les ordres
d'integration correspondants de la valeur de la fonction aux points et poids
de Gauss.
*/
//#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#define No_Standard_DimensionError
//#endif
#include <math_GaussMultipleIntegration.ixx>
#include <math.hxx>
#include <math_Matrix.hxx>
#include <math_Vector.hxx>
#include <math_IntegerVector.hxx>
#include <math_MultipleVarFunction.hxx>
class IntegrationFunction {
// Cette classe sert a conserver dans les champs les valeurs de tests de
// la fonction recursive.(En particulier le pointeur sur la fonction F,
// heritant d'une classe abstraite, non traite en cdl.)
math_MultipleVarFunction *Fsav;
math_IntegerVector Ordsav;
Standard_Integer NVarsav;
math_Vector xr;
math_Vector xm;
math_Matrix GaussPoint;
math_Matrix GaussWeight;
Standard_Real Val;
Standard_Boolean Done;
public:
IntegrationFunction(math_MultipleVarFunction& F,
const Standard_Integer maxsav, const Standard_Integer NVar,
const math_IntegerVector& Ord,
const math_Vector& Lowsav,
const math_Vector& Uppsav);
Standard_Real Value() ;
Standard_Boolean IsDone() const;
Standard_Boolean recursive_iteration(Standard_Integer& n, math_IntegerVector& inc);
};
IntegrationFunction::IntegrationFunction(math_MultipleVarFunction& F,
const Standard_Integer maxsav, const Standard_Integer NVar,
const math_IntegerVector& Ord,
const math_Vector& Lowsav,const math_Vector& Uppsav):
Ordsav(1, NVar),
xr(1, NVar),
xm(1, NVar),
GaussPoint(1, NVar, 1, maxsav),
GaussWeight(1, NVar, 1, maxsav)
{
Standard_Integer i, k;
math_IntegerVector inc(1, NVar);
inc.Init(0);
Fsav = &F;
NVarsav = NVar;
Ordsav = Ord;
Done = Standard_False;
//Recuperation des points et poids de Gauss dans le fichier GaussPoints
for (i =1; i<= NVarsav; i++) {
xm(i) = 0.5*(Lowsav(i) + Uppsav(i));
xr(i) = 0.5*(Uppsav(i) - Lowsav(i));
math_Vector GP(1,Ordsav(i)), GW(1,Ordsav(i));
math::GaussPoints(Ordsav(i),GP);
math::GaussWeights(Ordsav(i),GW);
for (k = 1; k <= Ordsav(i); k++) {
GaussPoint(i,k) = GP(k); //kieme point et poids de
GaussWeight(i,k) = GW(k);//Gauss de la variable i.
}
}
Val = 0.0;
Standard_Integer Iterdeb = 1;
Standard_Boolean recur = recursive_iteration(Iterdeb, inc);
if (recur) {
//On ramene l'integration a la bonne echelle.
for ( i = 1; i <= NVarsav; i++) {
Val *= xr(i);
}
Done = Standard_True;
}
}
Standard_Real IntegrationFunction::Value() {
return Val;
}
Standard_Boolean IntegrationFunction::IsDone() const{
return Done;
}
Standard_Boolean IntegrationFunction::recursive_iteration(Standard_Integer& n,
math_IntegerVector& inc) {
// Termination criterium :
// Calcul de la valeur de la fonction aux points de Gauss fixes:
int local;
if (n == (NVarsav+1)) {
math_Vector dx(1, NVarsav);
Standard_Integer j ;
for ( j = 1; j <= NVarsav; j++) {
dx(j) = xr(j)* GaussPoint(j, inc(j));
}
Standard_Real F1;
Standard_Boolean Ok = Fsav->Value(xm + dx, F1);
if (!Ok) {return Standard_False;};
Standard_Real Interm = 1;
for ( j = 1; j <= NVarsav; j++) {
Interm *= GaussWeight(j, inc(j));
}
Val += Interm*F1;
return Standard_True;
}
// Calcul recursif, pour chaque variable n de la valeur de la fonction aux
// Ordsav(n) points de Gauss.
Standard_Boolean OK=Standard_False;
for (inc(n) = 1; inc(n) <= Ordsav(n); inc(n)++) {
local = n + 1;
OK = recursive_iteration(local, inc);
}
return OK;
}
math_GaussMultipleIntegration::
math_GaussMultipleIntegration(math_MultipleVarFunction& F,
const math_Vector& Lower,
const math_Vector& Upper,
const math_IntegerVector& Order)
{
Standard_Integer MaxOrder = math::GaussPointsMax();
Standard_Integer i, max =0;
Standard_Integer NVar = F.NbVariables();
math_IntegerVector Ord(1, NVar);
math_Vector Lowsav(1, NVar);
math_Vector Uppsav(1, NVar);
Lowsav = Lower;
Uppsav = Upper;
// Ord = Order;
Done = Standard_False;
for (i = 1; i <= NVar; i++) {
if (Order(i) > MaxOrder) {
Ord(i) = MaxOrder;
}
else {
Ord(i) = Order(i);
}
if(Ord(i) >= max) {max = Ord(i);}
}
//Calcul de l'integrale aux points de Gauss.
// Il s agit d une somme multiple sur le domaine [Lower, Upper].
IntegrationFunction Func(F, max, NVar, Ord, Lowsav, Uppsav);
if (Func.IsDone()) {
Val = Func.Value();
Done = Standard_True;
}
}
void math_GaussMultipleIntegration::Dump(Standard_OStream& o) const {
o <<"math_GaussMultipleIntegration ";
if (Done) {
o << " Status = Done \n";
o << " Integration value = " << Val <<"\n";
}
else {
o << "Status = not Done \n";
}
}

View File

@@ -0,0 +1,18 @@
// math_GaussMultipleIntegration.lxx
#include <StdFail_NotDone.hxx>
inline Standard_Boolean math_GaussMultipleIntegration::IsDone() const
{ return Done; }
inline Standard_OStream& operator<<(Standard_OStream& o,
const math_GaussMultipleIntegration& G)
{
G.Dump(o);
return o;
}
inline Standard_Real math_GaussMultipleIntegration::Value() const{
StdFail_NotDone_Raise_if(!Done, " ");
return Val;
}

14
src/math/math_GaussPoints.hxx Executable file
View File

@@ -0,0 +1,14 @@
#ifndef math_GaussPoints_HeaderFile
#define math_GaussPoints_HeaderFile
#include <math_Vector.hxx>
#include <Standard_Real.hxx>
extern const Standard_Real Point[157];
extern const Standard_Real Weight[157];
math_Vector GPoints(const Standard_Integer Index);
math_Vector GWeights(const Standard_Integer Index);
#endif

View File

@@ -0,0 +1,64 @@
-- File: math_GaussSetIntegration.cdl
-- Created: Mon Jan 22 1996
-- Author: Philippe MANGIN
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1996
class GaussSetIntegration from math
---Purpose: -- This class implements the integration of a set of N
-- functions of M variables variables between the
-- parameter bounds Lower[a..b] and Upper[a..b].
-- Warning: - The case M>1 is not implemented.
uses Vector from math,
IntegerVector from math,
FunctionSet from math,
OStream from Standard,
NotDone from StdFail
raises NotDone, NotImplemented
is
Create(F: in out FunctionSet; Lower, Upper: Vector;
Order: IntegerVector)
---Purpose:
-- The Gauss-Legendre integration with Order = points of
-- integration for each unknow, is done on the function F
-- between the bounds Lower and Upper.
returns GaussSetIntegration
raises NotImplemented;
IsDone(me)
---Purpose: returns True if all has been correctly done.
---C++: inline
returns Boolean
is static;
Value(me)
---Purpose: returns the value of the integral.
---C++: inline
---C++: return const&
returns Vector
raises NotDone
is static;
Dump(me; o: in out OStream)
---Purpose: Prints information on the current state of the object.
is static;
fields
Val: Vector;
Done: Boolean;
end GaussSetIntegration;

View File

@@ -0,0 +1,85 @@
//#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#define No_Standard_DimensionError
//#endif
#include <math_GaussSetIntegration.ixx>
#include <math.hxx>
#include <math_Vector.hxx>
#include <math_FunctionSet.hxx>
math_GaussSetIntegration::math_GaussSetIntegration(math_FunctionSet& F,
const math_Vector& Lower,
const math_Vector& Upper,
const math_IntegerVector& Order)
: Val(1, F.NbEquations()) {
Standard_Integer NbEqua = F.NbEquations() , NbVar = F.NbVariables();
Standard_Integer i;
Standard_Boolean IsOk;
math_Vector FVal1(1, NbEqua), FVal2(1, NbEqua), Tval(1, NbVar);
// Verification
Standard_NotImplemented_Raise_if(
NbVar != 1 || Order.Value(Order.Lower()) > math::GaussPointsMax(),
"GaussSetIntegration ");
// Initialisations
Done = Standard_False;
Standard_Real Xdeb = Lower.Value( Lower.Lower() );
Standard_Real Xfin = Upper.Value( Upper.Lower() );
Standard_Integer Ordre = Order.Value(Order.Lower());
Standard_Real Xm, Xr;
math_Vector GaussP(1, Ordre), GaussW(1, Ordre);
// Recuperation des points de Gauss dans le fichier GaussPoints.
math::GaussPoints (Ordre, GaussP);
math::GaussWeights (Ordre, GaussW);
// Changement de variable pour la mise a l'echelle [Lower, Upper] :
Xm = 0.5 * (Xdeb + Xfin);
Xr = 0.5 * (Xfin - Xdeb);
Standard_Integer ind = Ordre/2, ind1 = (Ordre+1)/2;
if(ind1 > ind) { // odder case
Tval(1) = Xm; // + Xr * GaussP(ind1);
IsOk = F.Value(Tval, Val);
if (!IsOk) return;
Val *= GaussW(ind1);
}
else {
Val.Init(0);
}
for (i=1; i<= ind; i++) {
Tval(1) = Xm + Xr * GaussP(i);
IsOk = F.Value(Tval, FVal1);
if (!IsOk) return;
Tval(1) = Xm - Xr * GaussP(i);
IsOk = F.Value(Tval, FVal2);
if (!IsOk) return;
FVal1 += FVal2;
FVal1 *= GaussW(i);
Val += FVal1;
}
Val *= Xr;
Done = Standard_True;
}
void math_GaussSetIntegration::Dump(Standard_OStream& o) const
{
o <<"math_GaussSetIntegration ";
if (Done) {
o << " Status = Done \n";
o << "Integration Value = " << Val<<"\n";
}
else {
o << "Status = not Done \n";
}
}

View File

@@ -0,0 +1,14 @@
#include <math_Vector.hxx>
#include <StdFail_NotDone.hxx>
inline Standard_Boolean math_GaussSetIntegration::IsDone() const
{
return Done;
}
inline const math_Vector& math_GaussSetIntegration::Value() const
{
StdFail_NotDone_Raise_if(!Done, "Integration ");
return Val;
}

View File

@@ -0,0 +1,72 @@
-- File: GaussSingleIntegration.cdl
-- Created: Tue May 14 18:15:11 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class GaussSingleIntegration from math
---Purpose:
-- This class implements the integration of a function of a single variable
-- between the parameter bounds Lower and Upper.
-- Warning: Order must be inferior or equal to 61.
uses Function from math,
OStream from Standard
raises NotDone from StdFail
is
Create
returns GaussSingleIntegration;
Create(F: in out Function; Lower, Upper: Real; Order: Integer)
---Purpose:
-- The Gauss-Legendre integration with N = Order points of integration,
-- is done on the function F between the bounds Lower and Upper.
returns GaussSingleIntegration;
Create(F: in out Function; Lower, Upper: Real; Order: Integer; Tol: Real)
---Purpose:
-- The Gauss-Legendre integration with N = Order points of integration and
-- given tolerance = Tol is done on the function F between the bounds
-- Lower and Upper.
returns GaussSingleIntegration;
Perform(me: in out; F: in out Function; Lower, Upper: Real; Order: Integer)
---Purpose: perfoms actual computation
is private;
IsDone(me)
---Purpose: returns True if all has been correctly done.
---C++: inline
returns Boolean
is static;
Value(me)
---Purpose: returns the value of the integral.
---C++: inline
returns Real
raises NotDone
is static;
Dump(me; o: in out OStream)
---Purpose: Prints information on the current state of the object.
is static;
fields
Val: Real;
Done: Boolean;
end GaussSingleIntegration;

View File

@@ -0,0 +1,144 @@
//static const char* sccsid = "@(#)math_GaussSingleIntegration.cxx 3.3 95/01/25"; // Do not delete this line. Used by sccs.
// File math_GaussSingleIntegration.cxx
/*
Par Gauss le calcul d'une integrale simple se transforme en sommation des
valeurs de la fonction donnee aux <Order> points de Gauss affectee des poids
de Gauss.
Les points et poids de Gauss sont stockes dans GaussPoints.cxx.
Les points sont compris entre les valeurs -1 et +1, ce qui necessite un
changement de variable pour les faire varier dans l'intervalle [Lower, Upper].
On veut calculer Integrale( f(u)* du) entre a et b.
Etapes du calcul:
1- calcul de la fonction au ieme point de Gauss (apres changement de variable).
2- multiplication de cette valeur par le ieme poids de Gauss.
3- sommation de toutes ces valeurs.
4- retour a l'intervalle [Lower, Upper] de notre integrale.
*/
//#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#define No_Standard_DimensionError
//#endif
#include <math_GaussSingleIntegration.ixx>
#include <math.hxx>
#include <math_Vector.hxx>
#include <math_Function.hxx>
math_GaussSingleIntegration::math_GaussSingleIntegration() : Done(Standard_False)
{
}
math_GaussSingleIntegration::
math_GaussSingleIntegration(math_Function& F,
const Standard_Real Lower,
const Standard_Real Upper,
const Standard_Integer Order)
{
Standard_Integer theOrder = Min(math::GaussPointsMax(), Order);
Perform(F, Lower, Upper, theOrder);
}
math_GaussSingleIntegration::
math_GaussSingleIntegration(math_Function& F,
const Standard_Real Lower,
const Standard_Real Upper,
const Standard_Integer Order,
const Standard_Real Tol)
{
Standard_Integer theOrder = Min(math::GaussPointsMax(), Order);
const Standard_Integer IterMax = 13; // Max number of iteration
Standard_Integer NIter = 1; // current number of iteration
Standard_Integer NbInterval = 1; // current number of subintervals
Standard_Real dU,OldLen,Len;
Perform(F, Lower, Upper, theOrder);
Len = Val;
do {
OldLen = Len;
Len = 0.;
NbInterval *= 2;
dU = (Upper-Lower)/NbInterval;
for (Standard_Integer i=1; i<=NbInterval; i++) {
Perform(F, Lower+(i-1)*dU, Lower+i*dU, theOrder);
if (!Done) return;
Len += Val;
}
NIter++;
}
while (fabs(OldLen-Len) > Tol && NIter <= IterMax);
Val = Len;
}
void math_GaussSingleIntegration::Perform(math_Function& F,
const Standard_Real Lower,
const Standard_Real Upper,
const Standard_Integer Order)
{
Standard_Real xr, xm, dx;
Standard_Integer j;
Standard_Real F1, F2;
Standard_Boolean Ok1;
math_Vector GaussP(1, Order);
math_Vector GaussW(1, Order);
Done = Standard_False;
//Recuperation des points de Gauss dans le fichier GaussPoints.
math::GaussPoints(Order,GaussP);
math::GaussWeights(Order,GaussW);
// Calcul de l'integrale aux points de Gauss :
// Changement de variable pour la mise a l'echelle [Lower, Upper] :
xm = 0.5*(Upper + Lower);
xr = 0.5*(Upper - Lower);
Val = 0.;
Standard_Integer ind = Order/2, ind1 = (Order+1)/2;
if(ind1 > ind) { // odder case
Ok1 = F.Value(xm, Val);
if (!Ok1) return;
Val *= GaussW(ind1);
}
// Sommation sur tous les points de Gauss: avec utilisation de la symetrie.
for (j = 1; j <= ind; j++) {
dx = xr*GaussP(j);
Ok1 = F.Value(xm-dx, F1);
if(!Ok1) return;
Ok1 = F.Value(xm+dx, F2);
if(!Ok1) return;
// Multiplication par les poids de Gauss.
Standard_Real FT = F1+F2;
Val += GaussW(j)*FT;
}
// Mise a l'echelle de l'intervalle [Lower, Upper]
Val *= xr;
Done = Standard_True;
}
void math_GaussSingleIntegration::Dump(Standard_OStream& o) const {
o <<"math_GaussSingleIntegration ";
if (Done) {
o << " Status = Done \n";
o << "Integration Value = " << Val<<"\n";
}
else {
o << "Status = not Done \n";
}
}

View File

@@ -0,0 +1,18 @@
// File math_GaussSingleIntegration.lxx
#include <StdFail_NotDone.hxx>
inline Standard_OStream& operator<<(Standard_OStream& o,
const math_GaussSingleIntegration& G)
{
G.Dump(o);
return o;
}
inline Standard_Boolean math_GaussSingleIntegration::IsDone() const
{ return Done; }
inline Standard_Real math_GaussSingleIntegration::Value() const{
StdFail_NotDone_Raise_if(!Done, " ");
return Val;
}

128
src/math/math_Householder.cdl Executable file
View File

@@ -0,0 +1,128 @@
-- File: Householder.cdl
-- Created: Wed Aug 7 10:24:48 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class Householder from math
---Purpose: This class implements the least square solution of a set of
-- linear equations of m unknowns (n >= m) using the Householder
-- method. It solves A.X = B.
-- This algorithm has more numerical stability than
-- GaussLeastSquare but is longer.
-- It must be used if the matrix is singular or nearly singular.
-- It is about 16% longer than GaussLeastSquare if there is only
-- one member B to solve.
-- It is about 30% longer if there are twenty B members to solve.
uses Matrix from math,
Vector from math,
OStream from Standard
raises NotDone from StdFail,
OutOfRange from Standard,
DimensionError from Standard,
ConstructionError from Standard
is
Create(A, B: Matrix; EPS: Real = 1.0e-20)
---Purpose: Given an input matrix A with n>= m, given an input matrix B
-- this constructor performs the least square resolution of
-- the set of linear equations A.X = B for each column of B.
-- If a column norm is less than EPS, the resolution can't
-- be done.
-- Exception DimensionError is raised if the row number of B
-- is different from the A row number.
returns Householder
raises DimensionError;
Create(A, B: Matrix; lowerArow, upperArow, lowerAcol, upperAcol: Integer;
EPS: Real = 1.0e-20)
---Purpose: Given an input matrix A with n>= m, given an input matrix B
-- this constructor performs the least square resolution of
-- the set of linear equations A.X = B for each column of B.
-- If a column norm is less than EPS, the resolution can't
-- be done.
-- Exception DimensionError is raised if the row number of B
-- is different from the A row number.
returns Householder
raises DimensionError;
Create(A: Matrix; B: Vector; EPS: Real = 1.0e-20)
---Purpose: Given an input matrix A with n>= m, given an input vector B
-- this constructor performs the least square resolution of
-- the set of linear equations A.X = B.
-- If a column norm is less than EPS, the resolution can't
-- be done.
-- Exception DimensionError is raised if the length of B
-- is different from the A row number.
returns Householder
raises DimensionError;
Perform(me: in out; A, B: Matrix; EPS: Real)
---Purpose: This method is used internally for each constructor
-- above and can't be used directly.
is static protected;
IsDone(me)
---Purpose: Returns true if the computations are successful, otherwise returns false.
---C++: inline
returns Boolean
is static;
Value(me; sol : out Vector; Index: Integer = 1)
---Purpose: Given the integer Index, this routine returns the
-- corresponding least square solution sol.
-- Exception NotDone is raised if the resolution has not be
-- done.
-- Exception OutOfRange is raised if Index <=0 or
-- Index is more than the number of columns of B.
---C++: inline
raises NotDone, OutOfRange
is static;
AllValues(me)
---Purpose: Returns the matrix sol of all the solutions of the system
-- A.X = B.
-- Exception NotDone is raised is the resolution has not be
-- done.
---C++: inline
---C++: return const&
returns Matrix
raises NotDone, ConstructionError
is static;
Dump(me; o: in out OStream)
---Purpose: Prints informations on the current state of the object.
is static;
fields
Sol: Matrix;
Q: Matrix;
Done: Boolean;
mylowerArow: Integer;
myupperArow: Integer;
mylowerAcol: Integer;
myupperAcol: Integer;
end Householder;

172
src/math/math_Householder.cxx Executable file
View File

@@ -0,0 +1,172 @@
//static const char* sccsid = "@(#)math_Householder.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
//#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#define No_Standard_DimensionError
//#endif
#include <math_Householder.ixx>
#include <Standard_DimensionError.hxx>
#include <Standard_OutOfRange.hxx>
// Cette classe decrit la methode de Householder qui transforme A en un
// produit de matrice orthogonale par une triangulaire superieure. Les seconds
// membres sont modifies dans le meme temps.
// Les references sur le cote sont celles de l'algorithme explique en page
// 90 du livre "Introduction a l'analyse numerique matricielle et a
// l'optimisation." par P.G. CIARLET, edition MASSON. Les secondes
// references sont celles du sous-programme HOUSEO d'Euclid.
// A la difference du sous-programme Houseo, la premiere colonne n'est pas
// traitee separement. Les tests effectues ont montre que le code effectue
// specialement pour celle-ci etait plus long qu'une simple recopie. C'est
// donc cette solution de recopie initiale qui a ete retenue.
math_Householder::math_Householder(const math_Matrix& A, const math_Vector& B,
const Standard_Real EPS):
Sol(1, A.ColNumber(), 1, 1),
Q(1, A.RowNumber(),
1, A.ColNumber()) {
mylowerArow = A.LowerRow();
mylowerAcol = A.LowerCol();
myupperArow = A.UpperRow();
myupperAcol = A.UpperCol();
math_Matrix B1(1, B.Length(), 1, 1);
B1.SetCol(1, B);
Perform(A, B1, EPS);
}
math_Householder::math_Householder(const math_Matrix& A, const math_Matrix& B,
const Standard_Real EPS):
Sol(1, A.ColNumber(),
1, B.ColNumber()),
Q(1, A.RowNumber(),
A.LowerCol(), A.UpperCol()) {
mylowerArow = A.LowerRow();
mylowerAcol = A.LowerCol();
myupperArow = A.UpperRow();
myupperAcol = A.UpperCol();
Perform(A, B, EPS);
}
math_Householder::math_Householder(const math_Matrix& A, const math_Matrix& B,
const Standard_Integer lowerArow,
const Standard_Integer upperArow,
const Standard_Integer lowerAcol,
const Standard_Integer upperAcol,
const Standard_Real EPS):
Sol(1, upperAcol-lowerAcol+1,
1, B.ColNumber()),
Q(1, upperArow-lowerArow+1,
1, upperAcol-lowerAcol+1) {
mylowerArow = lowerArow;
myupperArow = upperArow;
mylowerAcol = lowerAcol;
myupperAcol = upperAcol;
Perform(A, B, EPS);
}
void math_Householder::Perform(const math_Matrix& A, const math_Matrix& B,
const Standard_Real EPS) {
Standard_Integer i, j, k, n, l, m;
Standard_Real scale, f, g, h = 0., alfaii;
Standard_Real qki;
Standard_Real cj;
n = Q.ColNumber();
l = Q.RowNumber();
m = B.ColNumber();
math_Matrix B2(1, l, 1, m);
Standard_Integer lbrow = B.LowerRow();
for (i = 1; i <= l; i++) {
for (j = 1; j <= n; j++) {
Q(i, j) = A(i+mylowerArow-1, j+mylowerAcol-1);
}
for (j=1; j <= m; j++) {
B2(i, j) = B(i+lbrow-1, j);
}
}
Standard_DimensionError_Raise_if(l != B.RowNumber() || n > l, " ");
// Traitement de chaque colonne de A:
for (i = 1; i <= n; i++) {
h = scale = 0.0;
for (k = i; k <= l; k++) {
qki = Q(k, i);
h += qki*qki; // = ||a||*||a|| = EUAI
}
f = Q(i,i); // = a1 = AII
g = f<1.e-15 ? Sqrt(h) : -Sqrt(h);
if (fabs(g) <= EPS) {
Done = Standard_False;
return;
}
h -= f*g; // = (v*v)/2 = C1
alfaii = g-f; // = v = ALFAII
for (j =i+1; j <= n; j++) {
scale = 0.0;
for (k = i; k <= l; k++) {
scale += Q(k,i)* Q(k,j); // = SCAL
}
cj = (g*Q(i,j) - scale)/h;
Q(i,j) = Q(i,j) - alfaii*cj;
for(k= i+1; k <= l; k++) {
Q(k,j) = Q(k, j) + cj * Q(k,i);
}
}
// Modification de B:
for (j = 1; j <= m; j++) {
scale= Q(i,i)*B2(i,j);
for (k = i+1; k <= l; k++) {
scale += Q(k,i)*B2(k,j);
}
cj = (g*B2(i,j) - scale)/h;
B2(i,j) = B2(i,j) - cj*alfaii;
for (k = i+1; k <= l; k++) {
B2(k,j) = B2(k,j) + cj*Q(k,i);
}
}
Q(i,i) = g;
}
// Remontee:
for (j = 1; j <= m; j++) {
Sol(n,j) = B2(n,j)/Q(n,n);
for (i = n -1; i >=1; i--) {
scale= 0.0;
for(k = i+1; k <= n; k++) {
scale += Q(i,k) * Sol(k,j);
}
Sol(i,j) = (B2(i,j) - scale)/Q(i,i);
}
}
Done = Standard_True;
}
void math_Householder::Dump(Standard_OStream& o) const {
o <<"math_Householder ";
if (Done) {
o << " Status = Done \n";
}
else {
o << "Status = not Done \n";
}
}

32
src/math/math_Householder.lxx Executable file
View File

@@ -0,0 +1,32 @@
// File math_Householder.lxx
#include <StdFail_NotDone.hxx>
inline Standard_Boolean math_Householder::IsDone() const {return Done; }
inline Standard_OStream& operator<<(Standard_OStream& o,
const math_Householder& H)
{
H.Dump(o);
return o;
}
inline void math_Householder::Value(math_Vector& sol,
const Standard_Integer Index) const {
StdFail_NotDone_Raise_if(!Done, " ");
Standard_OutOfRange_Raise_if((Index<1) || (Index>Sol.ColNumber()), " ");
sol = Sol.Col(Index);
}
inline const math_Matrix& math_Householder::AllValues() const {
StdFail_NotDone_Raise_if(!Done, " ");
return Sol;
}

39
src/math/math_IntegerRandom.cdl Executable file
View File

@@ -0,0 +1,39 @@
-- File: IntegerRandom.cdl
-- Created: Mon May 27 14:15:45 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class IntegerRandom from math
---Purpose:
-- This class implements an integer random number generator.
is
Create(Lower, Upper: Integer)
---Purpose:
-- creates a Integer random generator between the values Lower and Upper.
returns IntegerRandom;
Reset(me:in out)
---Purpose: reinitializes the random generator
is static;
Next(me: in out)
---Purpose: returns the next random number.
returns Integer
is static;
fields
Low: Integer;
Up: Integer;
Dummy: Integer;
end IntegerRandom;

27
src/math/math_IntegerRandom.cxx Executable file
View File

@@ -0,0 +1,27 @@
//static const char* sccsid = "@(#)math_IntegerRandom.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
#include <math_IntegerRandom.ixx>
#include <math_Recipes.hxx>
math_IntegerRandom::math_IntegerRandom(const Standard_Integer Lower,
const Standard_Integer Upper) {
Low = Lower;
Up = Upper;
Dummy=-1;
Random2(Dummy);
}
void math_IntegerRandom::Reset() {
Dummy=-1;
Random2(Dummy);
}
Standard_Integer math_IntegerRandom::Next() {
Standard_Real value=Random2(Dummy);
Standard_Integer Result=(Standard_Integer)(Standard_Real((Up-Low))*value + Low);
return (Result) ;
}

326
src/math/math_IntegerVector.cdl Executable file
View File

@@ -0,0 +1,326 @@
-- File: IntegerVector.cdl
-- Created: Mon May 6 14:55:20 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class IntegerVector from math
---Purpose:
-- This class implements the real IntegerVector abstract data type.
-- IntegerVectors can have an arbitrary range which must be define at
-- the declaration and cannot be changed after this declaration.
-- Example: math_IntegerVector V1(-3, 5); // an IntegerVector with
-- range [-3..5]
--
-- IntegerVector is copied through assignement :
-- math_IntegerVector V2( 1, 9);
-- ....
-- V2 = V1;
-- V1(1) = 2.0; // the IntegerVector V2 will not be modified.
--
-- The Exception RangeError is raised when trying to access outside
-- the range of an IntegerVector :
-- V1(11) = 0 // --> will raise RangeError;
--
-- The Exception DimensionError is raised when the dimensions of two
-- IntegerVectors are not compatible :
-- math_IntegerVector V3(1, 2);
-- V3 = V1; // --> will raise DimensionError;
-- V1.Add(V3) // --> will raise DimensionError;
uses Matrix from math,
SingleTabOfInteger from math,
OStream from Standard
raises DimensionError from Standard,
DivideByZero from Standard,
RangeError from Standard
is
Create(First, Last: Integer)
---Purpose: contructs an IntegerVector in the range [Lower..Upper]
returns IntegerVector;
Create(First, Last: Integer; InitialValue : Integer)
---Purpose: contructs an IntegerVector in the range [Lower..Upper]
-- with all the elements set to InitialValue.
returns IntegerVector;
Init(me : in out; InitialValue: Integer);
---Purpose: Initialize an IntegerVector with all the elements
-- set to InitialValue.
Create(Tab : Address; First, Last: Integer)
---Purpose: constructs an IntegerVector in the range [Lower..Upper]
-- which share the "c array" Tab.
returns IntegerVector;
Create(Other: IntegerVector)
---Purpose: constructs a copy for initialization.
-- An exception is raised if the lengths of the IntegerVectors
-- are different.
returns IntegerVector
raises DimensionError;
SetFirst(me: in out; First: Integer)
---Purpose: is used internally to set the Lower value of the
-- IntegerVector.
is static protected;
Length(me)
---Purpose: returns the length of an IntegerVector
---C++: inline
returns Integer
is static;
Lower(me)
---Purpose: returns the value of the Lower index of an IntegerVector.
---C++: inline
returns Integer
is static;
Upper(me)
---Purpose: returns the value of the Upper index of an IntegerVector.
---C++: inline
returns Integer
is static;
Norm(me)
---Purpose: returns the value of the norm of an IntegerVector.
returns Real
is static;
Norm2 (me)
---Purpose: returns the value of the square of the norm of an
-- IntegerVector.
returns Real
is static;
Max(me)
---Purpose: returns the value of the Index of the maximum element of
-- an IntegerVector.
returns Integer
is static;
Min(me)
---Purpose: returns the value of the Index of the minimum element
-- of an IntegerVector.
returns Integer
is static;
Invert(me: in out)
---Purpose: inverses an IntegerVector.
---Example: [1, 2, 3, 4] becomes [4, 3, 2, 1].
is static;
Inverse(me)
---Purpose: returns the inverse IntegerVector of an IntegerVector.
returns IntegerVector
is static;
Set(me: in out; I1, I2: Integer; V: IntegerVector)
---Purpose: sets an IntegerVector from <I1> to <I2> to the
-- IntegerVector <V>;
-- An exception is raised if I1<LowerIndex or I2>UpperIndex or I1>I2.
-- An exception is raised if I2-I1+1 is different from the Length of V.
raises DimensionError
is static;
Slice(me; I1, I2: Integer)
---Purpose: slices the values of the IntegerVector between <I1> and
-- <I2>:
-- Example: [2, 1, 2, 3, 4, 5] becomes [2, 4, 3, 2, 1, 5] between 2 and 5.
-- An exception is raised if I1<LowerIndex or I2>UpperIndex.
returns IntegerVector
raises DimensionError
is static;
Multiply (me: in out; Right: Integer)
---Purpose: returns the product of an IntegerVector by an integer value.
---C++: alias operator *=
raises DimensionError from Standard
is static;
Multiplied (me; Right: Integer)
---Purpose: returns the product of an IntegerVector by an integer value.
---C++: alias operator*
returns IntegerVector
raises DimensionError from Standard
is static;
TMultiplied (me; Right: Integer)
---Purpose: returns the product of a vector and a real value.
---C++: alias "friend math_IntegerVector operator *(const Standard_Integer Left,const math_IntegerVector& Right);"
returns IntegerVector
is static;
Add (me: in out; Right: IntegerVector)
---Purpose: adds the IntegerVector <Right> to an IntegerVector.
-- An exception is raised if the IntegerVectors have not the same
-- length.
-- An exception is raised if the lengths are not equal.
---C++: alias operator +=
raises DimensionError
is static;
Added (me; Right: IntegerVector)
---Purpose: adds the IntegerVector <Right> to an IntegerVector.
-- An exception is raised if the IntegerVectors have not the same
-- length.
-- An exception is raised if the lengths are not equal.
---C++:alias operator+
returns IntegerVector
raises DimensionError
is static;
Add (me: in out; Left, Right: IntegerVector)
---Purpose: sets an IntegerVector to the sum of the IntegerVector
-- <Left> and the IntegerVector <Right>.
-- An exception is raised if the lengths are different.
raises DimensionError
is static;
Subtract(me: in out; Left, Right: IntegerVector)
---Purpose: sets an IntegerVector to the substraction of
-- <Right> from <Left>.
-- An exception is raised if the IntegerVectors have not the same
-- length.
raises DimensionError
is static;
Value(me; Num: Integer)
---Purpose: accesses (in read or write mode) the value of index Num of
-- an IntegerVector.
---C++: alias operator()
---C++: return &
---C++: inline
returns Integer
raises RangeError from Standard
is static;
Initialized(me: in out; Other: IntegerVector)
---Purpose: Initialises an IntegerVector by copying <Other>.
-- An exception is raised if the Lengths are different.
---C++: alias operator=
---C++: return &
returns IntegerVector
raises DimensionError
is static;
Multiplied(me; Right: IntegerVector)
---Purpose: returns the inner product of 2 IntegerVectors.
-- An exception is raised if the lengths are not equal.
---C++: alias operator*
returns Integer
raises DimensionError
is static;
Opposite(me: in out)
---Purpose: returns the opposite of an IntegerVector.
---C++: alias operator-
returns IntegerVector
is static;
Subtract(me: in out; Right: IntegerVector)
---Purpose: returns the subtraction of <Right> from <me>.
-- An exception is raised if the IntegerVectors have not the same length.
---C++: alias operator-=
raises DimensionError
is static;
Subtracted(me; Right: IntegerVector)
---Purpose: returns the subtraction of <Right> from <me>.
-- An exception is raised if the IntegerVectors have not the same length.
---C++: alias operator-
returns IntegerVector
raises DimensionError
is static;
Multiply(me: in out; Left: Integer; Right: IntegerVector)
---Purpose: returns the multiplication of an integer by an
-- IntegerVector.
raises DimensionError
is static;
Dump(me; o: in out OStream)
---Purpose: Prints on the stream o information on the current state
-- of the object.
-- Is used to redefine the operator <<.
is static;
fields
FirstIndex: Integer;
LastIndex: Integer;
Array: SingleTabOfInteger;
friends
class Matrix from math
end IntegerVector;

354
src/math/math_IntegerVector.cxx Executable file
View File

@@ -0,0 +1,354 @@
//static const char* sccsid = "@(#)math_IntegerVector.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
//#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#define No_Standard_DimensionError
//#endif
#include <math_IntegerVector.ixx>
#include <Standard_DimensionError.hxx>
#include <Standard_RangeError.hxx>
math_IntegerVector::math_IntegerVector(const Standard_Integer First,
const Standard_Integer Last):
FirstIndex(First),
LastIndex(Last),
Array(First, Last) {
Standard_RangeError_Raise_if(First > Last, " ");
}
math_IntegerVector::math_IntegerVector(const Standard_Integer First,
const Standard_Integer Last,
const Standard_Integer InitialValue):
FirstIndex(First),
LastIndex(Last),
Array(First, Last) {
Standard_RangeError_Raise_if(First > Last, " ");
Array.Init(InitialValue);
}
math_IntegerVector::math_IntegerVector(const Standard_Address Tab,
const Standard_Integer First,
const Standard_Integer Last) :
FirstIndex(First),
LastIndex(Last),
Array(*((const Standard_Integer *)Tab),
First, Last)
{
Standard_RangeError_Raise_if(First > Last, " ");
}
void math_IntegerVector::Init(const Standard_Integer InitialValue)
{
Array.Init(InitialValue);
}
math_IntegerVector::math_IntegerVector(const math_IntegerVector& Other):
FirstIndex(Other.FirstIndex),
LastIndex(Other.LastIndex),
Array(Other.Array) {}
void math_IntegerVector::SetFirst(const Standard_Integer First) {
Array.SetLower(First);
LastIndex = LastIndex - FirstIndex + First;
FirstIndex = First;
}
Standard_Real math_IntegerVector::Norm() const {
Standard_Real Result = 0;
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
Result = Result + Array(Index) * Array(Index);
}
return Sqrt(Result);
}
Standard_Real math_IntegerVector::Norm2() const {
Standard_Real Result = 0;
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
Result = Result + Array(Index) * Array(Index);
}
return Result;
}
Standard_Integer math_IntegerVector::Max() const {
Standard_Integer I=0;
Standard_Real X = RealFirst();
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
if(Array(Index) > X) {
X = Array(Index);
I = Index;
}
}
return I;
}
Standard_Integer math_IntegerVector::Min() const {
Standard_Integer I=0;
Standard_Real X = RealLast();
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
if(Array(Index) < X) {
X = Array(Index);
I = Index;
}
}
return I;
}
void math_IntegerVector::Invert() {
Standard_Integer J;
Standard_Integer Temp;
for(Standard_Integer Index = FirstIndex;
Index <= FirstIndex + Length() / 2 ; Index++) {
J = LastIndex + FirstIndex - Index;
Temp = Array(Index);
Array(Index) = Array(J);
Array(J) = Temp;
}
}
math_IntegerVector math_IntegerVector::Inverse() const {
math_IntegerVector Result = *this;
Result.Invert();
return Result;
}
void math_IntegerVector::Set(const Standard_Integer I1,
const Standard_Integer I2,
const math_IntegerVector &V) {
Standard_DimensionError_Raise_if((I1 < FirstIndex) ||
(I2 > LastIndex) ||
(I1 > I2) ||
(I2 - I1 + 1 != V.Length()), " ");
Standard_Integer I = V.Lower();
for(Standard_Integer Index = I1; Index <= I2; Index++) {
Array(Index) = V.Array(I);
I++;
}
}
void math_IntegerVector::Multiply(const Standard_Integer Right) {
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
Array(Index) = Array(Index) * Right;
}
}
void math_IntegerVector::Add(const math_IntegerVector& Right) {
Standard_DimensionError_Raise_if(Length() != Right.Length(), " ");
Standard_Integer I = Right.FirstIndex;
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
Array(Index) = Array(Index) + Right.Array(I);
I++;
}
}
void math_IntegerVector::Subtract(const math_IntegerVector& Right) {
Standard_DimensionError_Raise_if(Length() != Right.Length(), " ");
Standard_Integer I = Right.FirstIndex;
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
Array(Index) = Array(Index) - Right.Array(I);
I++;
}
}
math_IntegerVector math_IntegerVector::Slice(const Standard_Integer I1,
const Standard_Integer I2) const {
Standard_DimensionError_Raise_if((I1 < FirstIndex) || (I1 > LastIndex) ||
(I2 < FirstIndex) || (I2 > LastIndex),
" ");
if(I2 >= I1) {
math_IntegerVector Result(I1, I2);
for(Standard_Integer Index = I1; Index <= I2; Index++) {
Result.Array(Index) = Array(Index);
}
return Result;
}
else {
math_IntegerVector Result(I2, I1);
for(Standard_Integer Index = I1; Index >= I2; Index--) {
Result.Array(Index) = Array(Index);
}
return Result;
}
}
Standard_Integer math_IntegerVector::Multiplied (const math_IntegerVector& Right) const {
Standard_Integer Result = 0;
Standard_DimensionError_Raise_if(Length() != Right.Length(), " ");
Standard_Integer I = Right.FirstIndex;
for(Standard_Integer Index = 0; Index < Length(); Index++) {
Result = Result + Array(Index) * Right.Array(I);
I++;
}
return Result;
}
math_IntegerVector math_IntegerVector::Multiplied (const Standard_Integer Right)const {
math_IntegerVector Result(FirstIndex, LastIndex);
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
Result.Array(Index) = Array(Index) * Right;
}
return Result;
}
math_IntegerVector math_IntegerVector::TMultiplied (const Standard_Integer Right)const {
math_IntegerVector Result(FirstIndex, LastIndex);
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
Result.Array(Index) = Array(Index) * Right;
}
return Result;
}
math_IntegerVector math_IntegerVector::Added (const math_IntegerVector& Right) const {
Standard_DimensionError_Raise_if(Length() != Right.Length(), " ");
math_IntegerVector Result(FirstIndex, LastIndex);
Standard_Integer I = Right.FirstIndex;
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
Result.Array(Index) = Array(Index) + Right.Array(I);
I++;
}
return Result;
}
math_IntegerVector math_IntegerVector::Opposite() {
math_IntegerVector Result(FirstIndex, LastIndex);
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
Result.Array(Index) = - Array(Index);
}
return Result;
}
math_IntegerVector math_IntegerVector::Subtracted (const math_IntegerVector& Right) const {
Standard_DimensionError_Raise_if(Length() != Right.Length(), " ");
math_IntegerVector Result(FirstIndex, LastIndex);
Standard_Integer I = Right.FirstIndex;
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
Result.Array(Index) = Array(Index) - Right.Array(I);
I++;
}
return Result;
}
void math_IntegerVector::Add (const math_IntegerVector& Left,
const math_IntegerVector& Right) {
Standard_DimensionError_Raise_if((Length() != Right.Length()) ||
(Right.Length() != Left.Length()), " ");
Standard_Integer I = Left.FirstIndex;
Standard_Integer J = Right.FirstIndex;
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
Array(Index) = Left.Array(I) + Right.Array(J);
I++;
J++;
}
}
void math_IntegerVector::Subtract (const math_IntegerVector& Left,
const math_IntegerVector& Right) {
Standard_DimensionError_Raise_if((Length() != Right.Length()) ||
(Right.Length() != Left.Length()), " ");
Standard_Integer I = Left.FirstIndex;
Standard_Integer J = Right.FirstIndex;
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
Array(Index) = Left.Array(I) - Right.Array(J);
I++;
J++;
}
}
void math_IntegerVector::Multiply(const Standard_Integer Left,
const math_IntegerVector& Right)
{
Standard_DimensionError_Raise_if((Length() != Right.Length()),
" ");
for(Standard_Integer I = FirstIndex; I <= LastIndex; I++) {
Array(I) = Left * Right.Array(I);
}
}
math_IntegerVector& math_IntegerVector::Initialized (const math_IntegerVector& Other) {
Standard_DimensionError_Raise_if(Length() != Other.Length(), " ");
#ifdef DEB
Standard_Integer I = Other.FirstIndex;
#endif
(Other.Array).Copy(Array);
return *this;
}
void math_IntegerVector::Dump(Standard_OStream& o) const
{
o << "math_IntegerVector of Range = " << Length() << "\n";
for(Standard_Integer Index = FirstIndex; Index <= LastIndex; Index++) {
o << "math_IntegerVector(" << Index << ") = " << Array(Index) << "\n";
}
}

41
src/math/math_IntegerVector.lxx Executable file
View File

@@ -0,0 +1,41 @@
// File math_IntegerVector.lxx
// lpa, le 29/10/91
#include <Standard_DimensionError.hxx>
inline Standard_OStream& operator<<(Standard_OStream& o,
const math_IntegerVector& vec)
{
vec.Dump(o);
return o;
}
inline math_IntegerVector operator* (const Standard_Integer Left,
const math_IntegerVector& Right)
{
return Right.Multiplied(Left);
}
inline Standard_Integer math_IntegerVector::Length() const
{ return LastIndex - FirstIndex +1;}
// length of a IntegerVector.
inline Standard_Integer math_IntegerVector::Lower() const
{ return FirstIndex;}
// value of the lower index of a IntegerVector.
inline Standard_Integer math_IntegerVector::Upper() const
{return LastIndex;}
// value of the Upper index of a IntegerVector.
inline Standard_Integer& math_IntegerVector::Value(const Standard_Integer Num) const {
Standard_RangeError_Raise_if(Num < FirstIndex || Num > LastIndex, " ");
return Array(Num);
}

95
src/math/math_Jacobi.cdl Executable file
View File

@@ -0,0 +1,95 @@
-- File: Jacobi.cdl
-- Created: Tue May 14 18:21:21 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class Jacobi from math
---Purpose:
-- This class implements the Jacobi method to find the eigenvalues and
-- the eigenvectors of a real symmetric square matrix.
-- A sort of eigenvalues is done.
uses Vector from math,
Matrix from math,
OStream from Standard
raises NotDone from StdFail
is
Create(A: Matrix)
---Purpose:
-- Given a Real n X n matrix A, this constructor computes all its
-- eigenvalues and eigenvectors using the Jacobi method.
-- The exception NotSquare is raised if the matrix is not square.
-- No verification that the matrix A is really symmetric is done.
returns Jacobi;
IsDone(me)
---Purpose: Returns true if the computations are successful, otherwise returns false.
---C++: inline
returns Boolean
is static;
Values(me)
---Purpose: Returns the eigenvalues vector.
-- Exception NotDone is raised if calculation is not done successfully.
---C++: inline
---C++: return const&
returns Vector
raises NotDone
is static;
Value(me; Num: Integer)
---Purpose: returns the eigenvalue number Num.
-- Eigenvalues are in the range (1..n).
-- Exception NotDone is raised if calculation is not done successfully.
---C++: inline
returns Real
raises NotDone
is static;
Vectors(me)
---Purpose: returns the eigenvectors matrix.
-- Exception NotDone is raised if calculation is not done successfully.
---C++: inline
---C++: return const&
returns Matrix
raises NotDone
is static;
Vector(me; Num: Integer; V : out Vector)
---Purpose: Returns the eigenvector V of number Num.
-- Eigenvectors are in the range (1..n).
-- Exception NotDone is raised if calculation is not done successfully.
---C++: inline
raises NotDone
is static;
Dump(me; o: in out OStream)
---Purpose: Prints information on the current state of the object.
-- Is used to redefine the operator <<.
is static;
fields
Done: Boolean;
AA: Matrix;
NbRotations: Integer;
EigenValues: Vector;
EigenVectors: Matrix;
end Jacobi;

45
src/math/math_Jacobi.cxx Executable file
View File

@@ -0,0 +1,45 @@
//static const char* sccsid = "@(#)math_Jacobi.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
//#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#define No_Standard_DimensionError
//#endif
#include <math_Jacobi.ixx>
#include <math_Recipes.hxx>
#include <math_NotSquare.hxx>
math_Jacobi::math_Jacobi(const math_Matrix& A) : AA(1, A.RowNumber(),
1, A.RowNumber()),
EigenValues(1, A.RowNumber()),
EigenVectors(1, A.RowNumber(),
1, A.RowNumber()) {
math_NotSquare_Raise_if(A.RowNumber() != A.ColNumber(), " ");
AA = A;
Standard_Integer Error = Jacobi(AA, EigenValues, EigenVectors, NbRotations);
if(!Error) {
Done = Standard_True;
}
else {
Done = Standard_False;
}
}
void math_Jacobi::Dump(Standard_OStream& o) const {
o <<"math_Jacobi ";
if (Done) {
o << " Status = Done \n";
o << " The eigenvalues vector is: " << EigenValues << endl;
}
else {
o << "Status = not Done \n";
}
}

38
src/math/math_Jacobi.lxx Executable file
View File

@@ -0,0 +1,38 @@
// math_Jacobi.lxx
#include <StdFail_NotDone.hxx>
#include <math_Vector.hxx>
#include <math_Matrix.hxx>
inline Standard_Boolean math_Jacobi::IsDone() const { return Done; }
inline Standard_OStream& operator<<(Standard_OStream& o,
const math_Jacobi& J)
{
J.Dump(o);
return o;
}
inline const math_Vector& math_Jacobi::Values () const{
StdFail_NotDone_Raise_if(!Done, " ");
return EigenValues;
}
inline Standard_Real math_Jacobi::Value (const Standard_Integer Num) const{
StdFail_NotDone_Raise_if(!Done, " ");
return EigenValues(Num);
}
inline const math_Matrix& math_Jacobi::Vectors() const{
StdFail_NotDone_Raise_if(!Done, " ");
return EigenVectors;
}
inline void math_Jacobi::Vector (const Standard_Integer Num, math_Vector& V) const{
StdFail_NotDone_Raise_if(!Done, " ");
V = EigenVectors.Col(Num);
}

3977
src/math/math_Kronrod.cxx Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,135 @@
-- File: math_KronrodSingleIntegration.cdl
-- Created: Thu Dec 8 14:44:35 2005
-- Author: Sergey KHROMOV
-- <skv@dimox>
---Copyright: Matra Datavision 2005
class KronrodSingleIntegration from math
---Purpose: This class implements the Gauss-Kronrod method of
-- integral computation.
uses
Function from math,
Vector from math,
Real from Standard,
Integer from Standard,
Boolean from Standard
raises
NotDone from StdFail
is
Create
---Purpose: An empty constructor.
returns KronrodSingleIntegration;
Create(theFunction : in out Function from math;
theLower : Real from Standard;
theUpper : Real from Standard;
theNbPnts : Integer from Standard)
---Purpose: Constructor. Takes the function, the lower and upper bound
-- values, the initial number of Kronrod points
returns KronrodSingleIntegration;
Create(theFunction : in out Function from math;
theLower : Real from Standard;
theUpper : Real from Standard;
theNbPnts : Integer from Standard;
theTolerance: Real from Standard;
theMaxNbIter: Integer from Standard)
---Purpose: Constructor. Takes the function, the lower and upper bound
-- values, the initial number of Kronrod points, the
-- tolerance value and the maximal number of iterations as
-- parameters.
returns KronrodSingleIntegration;
Perform(me: in out; theFunction : in out Function from math;
theLower : Real from Standard;
theUpper : Real from Standard;
theNbPnts : Integer from Standard);
---Purpose: Computation of the integral. Takes the function,
-- the lower and upper bound values, the initial number
-- of Kronrod points, the relative tolerance value and the
-- maximal number of iterations as parameters.
-- theNbPnts should be odd and greater then or equal to 3.
Perform(me: in out; theFunction : in out Function from math;
theLower : Real from Standard;
theUpper : Real from Standard;
theNbPnts : Integer from Standard;
theTolerance: Real from Standard;
theMaxNbIter: Integer from Standard);
---Purpose: Computation of the integral. Takes the function,
-- the lower and upper bound values, the initial number
-- of Kronrod points, the relative tolerance value and the
-- maximal number of iterations as parameters.
-- theNbPnts should be odd and greater then or equal to 3.
-- Note that theTolerance is relative, i.e. the criterion of
-- solution reaching is:
-- Abs(Kronrod - Gauss)/Abs(Kronrod) < theTolerance.
-- theTolerance should be positive.
IsDone(me)
---Purpose: Returns Standard_True if computation is performed
-- successfully.
---C++: inline
returns Boolean from Standard;
Value(me)
---Purpose: Returns the value of the integral.
---C++: inline
returns Real from Standard
raises NotDone;
ErrorReached(me)
---Purpose: Returns the value of the relative error reached.
---C++: inline
returns Real from Standard
raises NotDone;
AbsolutError(me)
---Purpose: Returns the value of the relative error reached.
---C++: inline
returns Real from Standard
raises NotDone;
OrderReached(me)
---Purpose: Returns the number of Kronrod points
-- for which the result is computed.
---C++: inline
returns Integer from Standard
raises NotDone;
NbIterReached(me)
---Purpose: Returns the number of iterations
-- that were made to compute result.
---C++: inline
returns Integer from Standard
raises NotDone;
GKRule(myclass;
theFunction : in out Function from math;
theLower : Real from Standard;
theUpper : Real from Standard;
theGaussP : Vector from math;
theGaussW : Vector from math;
theKronrodP : Vector from math;
theKronrodW : Vector from math;
theValue : in out Real from Standard;
theError : in out Real from Standard)
returns Boolean from Standard;
fields
myIsDone : Boolean from Standard;
myValue : Real from Standard;
myErrorReached : Real from Standard;
myAbsolutError : Real from Standard;
myNbPntsReached: Integer from Standard;
myNbIterReached: Integer from Standard;
end KronrodSingleIntegration;

View File

@@ -0,0 +1,356 @@
// File: math_KronrodSingleIntegration.cxx
// Created: Thu Dec 8 15:08:52 2005
// Author: Sergey KHROMOV
// <skv@dimox>
#include <math_KronrodSingleIntegration.ixx>
#include <math_Vector.hxx>
#include <math.hxx>
#include <TColStd_SequenceOfReal.hxx>
//==========================================================================
//function : An empty constructor.
//
//==========================================================================
math_KronrodSingleIntegration::math_KronrodSingleIntegration() :
myIsDone(Standard_False),
myValue(0.),
myErrorReached(0.),
myNbPntsReached(0),
myNbIterReached(0)
{
}
//==========================================================================
//function : Constructor
//
//==========================================================================
math_KronrodSingleIntegration::math_KronrodSingleIntegration
( math_Function &theFunction,
const Standard_Real theLower,
const Standard_Real theUpper,
const Standard_Integer theNbPnts):
myIsDone(Standard_False),
myValue(0.),
myErrorReached(0.),
myNbPntsReached(0)
{
Perform(theFunction, theLower, theUpper, theNbPnts);
}
//==========================================================================
//function : Constructor
//
//==========================================================================
math_KronrodSingleIntegration::math_KronrodSingleIntegration
( math_Function &theFunction,
const Standard_Real theLower,
const Standard_Real theUpper,
const Standard_Integer theNbPnts,
const Standard_Real theTolerance,
const Standard_Integer theMaxNbIter) :
myIsDone(Standard_False),
myValue(0.),
myErrorReached(0.),
myNbPntsReached(0)
{
Perform(theFunction, theLower, theUpper, theNbPnts,
theTolerance, theMaxNbIter);
}
//==========================================================================
//function : Perform
// Computation of the integral.
//==========================================================================
void math_KronrodSingleIntegration::Perform
( math_Function &theFunction,
const Standard_Real theLower,
const Standard_Real theUpper,
const Standard_Integer theNbPnts)
{
const Standard_Real aMinVol = Epsilon(1.);
const Standard_Real aPtol = 1.e-9;
myNbIterReached = 0;
if (theNbPnts < 3 ) {
myIsDone = Standard_False;
return;
}
if(theUpper - theLower < aPtol) {
myIsDone = Standard_False;
return;
}
// Get an odd value of number of initial points.
myNbPntsReached = (theNbPnts%2 == 0) ? theNbPnts + 1 : theNbPnts;
myErrorReached = RealLast();
Standard_Integer aNGauss = myNbPntsReached/2;
math_Vector aKronrodP(1, myNbPntsReached);
math_Vector aKronrodW(1, myNbPntsReached);
math_Vector aGaussP(1, aNGauss);
math_Vector aGaussW(1, aNGauss);
if (!math::KronrodPointsAndWeights(myNbPntsReached, aKronrodP, aKronrodW) ||
!math::OrderedGaussPointsAndWeights(aNGauss, aGaussP, aGaussW)) {
myIsDone = Standard_False;
return;
}
myIsDone = GKRule(theFunction, theLower, theUpper, aGaussP, aGaussW, aKronrodP, aKronrodW,
myValue, myErrorReached);
if(!myIsDone) return;
Standard_Real anAbsVal = Abs(myValue);
myAbsolutError = myErrorReached;
//if (anAbsVal > aMinVol)
//myErrorReached /= anAbsVal;
myNbIterReached++;
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
void math_KronrodSingleIntegration::Perform
( math_Function &theFunction,
const Standard_Real theLower,
const Standard_Real theUpper,
const Standard_Integer theNbPnts,
const Standard_Real theTolerance,
const Standard_Integer theMaxNbIter)
{
Standard_Real aMinVol = Epsilon(1.);
myNbIterReached = 0;
// Check prerequisites.
if (theNbPnts < 3 ||
theTolerance <= 0.) {
myIsDone = Standard_False;
return;
}
// Get an odd value of number of initial points.
myNbPntsReached = (theNbPnts%2 == 0) ? theNbPnts + 1 : theNbPnts;
Standard_Integer aNGauss = myNbPntsReached/2;
math_Vector aKronrodP(1, myNbPntsReached);
math_Vector aKronrodW(1, myNbPntsReached);
math_Vector aGaussP(1, aNGauss);
math_Vector aGaussW(1, aNGauss);
if (!math::KronrodPointsAndWeights(myNbPntsReached, aKronrodP, aKronrodW) ||
!math::OrderedGaussPointsAndWeights(aNGauss, aGaussP, aGaussW)) {
myIsDone = Standard_False;
return;
}
//First iteration
myIsDone = GKRule(theFunction, theLower, theUpper, aGaussP, aGaussW, aKronrodP, aKronrodW,
myValue, myErrorReached);
if(!myIsDone) return;
Standard_Real anAbsVal = Abs(myValue);
myAbsolutError = myErrorReached;
if (anAbsVal > aMinVol)
myErrorReached /= anAbsVal;
myNbIterReached++;
if(myErrorReached <= theTolerance) return;
if(myNbIterReached >= theMaxNbIter) return;
TColStd_SequenceOfReal anIntervals;
TColStd_SequenceOfReal anErrors;
TColStd_SequenceOfReal aValues;
anIntervals.Append(theLower);
anIntervals.Append(theUpper);
anErrors.Append(myAbsolutError);
aValues.Append(myValue);
Standard_Integer i, nint, nbints;
Standard_Real maxerr;
Standard_Integer count = 0;
while(myErrorReached > theTolerance && myNbIterReached < theMaxNbIter) {
//Searching interval with max error
nbints = anIntervals.Length() - 1;
nint = 0;
maxerr = 0.;
for(i = 1; i <= nbints; ++i) {
if(anErrors(i) > maxerr) {
maxerr = anErrors(i);
nint = i;
}
}
Standard_Real a = anIntervals(nint);
Standard_Real b = anIntervals(nint+1);
Standard_Real c = 0.5*(a + b);
Standard_Real v1, v2, e1, e2;
myIsDone = GKRule(theFunction, a, c, aGaussP, aGaussW, aKronrodP, aKronrodW,
v1, e1);
if(!myIsDone) return;
myIsDone = GKRule(theFunction, c, b, aGaussP, aGaussW, aKronrodP, aKronrodW,
v2, e2);
if(!myIsDone) return;
myNbIterReached++;
Standard_Real deltav = v1 + v2 - aValues(nint);
myValue += deltav;
if(Abs(deltav) <= Epsilon(Abs(myValue))) ++count;
Standard_Real deltae = e1 + e2 - anErrors(nint);
myAbsolutError += deltae;
if(myAbsolutError <= Epsilon(Abs(myValue))) ++count;
if(Abs(myValue) > aMinVol) myErrorReached = myAbsolutError/Abs(myValue);
else myErrorReached = myAbsolutError;
if(count > 50) return;
//Inserting new interval
anIntervals.InsertAfter(nint, c);
anErrors(nint) = e1;
anErrors.InsertAfter(nint, e2);
aValues(nint) = v1;
aValues.InsertAfter(nint, v2);
}
}
//=======================================================================
//function : GKRule
//purpose :
//=======================================================================
Standard_Boolean math_KronrodSingleIntegration::GKRule(
math_Function &theFunction,
const Standard_Real theLower,
const Standard_Real theUpper,
const math_Vector& theGaussP,
const math_Vector& theGaussW,
const math_Vector& theKronrodP,
const math_Vector& theKronrodW,
Standard_Real& theValue,
Standard_Real& theError)
{
Standard_Boolean IsDone;
Standard_Integer aNGauss = theGaussP.Length();
Standard_Integer aNKronrod = theKronrodP.Length();
Standard_Real aGaussVal;
Standard_Integer aNPnt2 = (aNKronrod + 1)/2;
Standard_Integer i;
Standard_Real aDx;
Standard_Real aVal1;
Standard_Real aVal2;
math_Vector f1(1, aNPnt2-1);
math_Vector f2(1, aNPnt2-1);
Standard_Real aXm = 0.5*(theUpper + theLower);
Standard_Real aXr = 0.5*(theUpper - theLower);
// Compute Gauss quadrature
aGaussVal = 0.;
theValue = 0.;
for (i = 2; i < aNPnt2; i += 2) {
aDx = aXr*theKronrodP.Value(i);
if (!theFunction.Value(aXm + aDx, aVal1) ||
!theFunction.Value(aXm - aDx, aVal2)) {
IsDone = Standard_False;
return IsDone;
}
f1(i) = aVal1;
f2(i) = aVal2;
aGaussVal += (aVal1 + aVal2)*theGaussW.Value(i/2);
theValue += (aVal1 + aVal2)*theKronrodW.Value(i);
}
// Compute value in the middle point.
if (!theFunction.Value(aXm, aVal1)) {
IsDone = Standard_False;
return IsDone;
}
Standard_Real fc = aVal1;
theValue += aVal1*theKronrodW.Value(aNPnt2);
if (i == aNPnt2)
aGaussVal += aVal1*theGaussW.Value(aNPnt2/2);
// Compute Kronrod quadrature
for (i = 1; i < aNPnt2; i += 2) {
aDx = aXr*theKronrodP.Value(i);
if (!theFunction.Value(aXm + aDx, aVal1) ||
!theFunction.Value(aXm - aDx, aVal2)) {
IsDone = Standard_False;
return IsDone;
}
f1(i) = aVal1;
f2(i) = aVal2;
theValue += (aVal1 + aVal2)*theKronrodW.Value(i);
}
Standard_Real mean = 0.5*theValue;
Standard_Real asc = Abs(fc-mean)*theKronrodW.Value(aNPnt2);
for(i = 1; i < aNPnt2; ++i) {
asc += theKronrodW.Value(i)*(Abs(f1(i) - mean) + Abs(f2(i) - mean));
}
asc *= aXr;
theValue *= aXr;
aGaussVal *= aXr;
// Compute the error and the new number of Kronrod points.
theError = Abs(theValue - aGaussVal);
Standard_Real scale =1.;
if(asc != 0. && theError != 0.) scale = Pow((200.*theError/asc), 1.5);
if(scale < 1.) theError = Min(theError, asc*scale);
//theFunction.GetStateNumber();
return Standard_True;
}

View File

@@ -0,0 +1,73 @@
// File: math_KronrodSingleIntegration.lxx
// Created: Thu Dec 8 15:16:08 2005
// Author: Sergey KHROMOV
// <skv@dimox>
#include <StdFail_NotDone.hxx>
//==========================================================================
//function : IsDone
// Returns Standard_True if computation is performed successfully.
//==========================================================================
inline Standard_Boolean math_KronrodSingleIntegration::IsDone() const
{
return myIsDone;
}
//==========================================================================
//function : Value
// Returns the value of the integral.
//==========================================================================
inline Standard_Real math_KronrodSingleIntegration::Value() const
{
StdFail_NotDone_Raise_if(!myIsDone, "math_KronrodSingleIntegration");
return myValue;
}
//==========================================================================
//function : ErrorReached
// Returns the value of the relative error reached.
//==========================================================================
inline Standard_Real math_KronrodSingleIntegration::ErrorReached() const
{
StdFail_NotDone_Raise_if(!myIsDone, "math_KronrodSingleIntegration");
return myErrorReached;
}
//=======================================================================
//function : AbsolutError
//purpose :
//=======================================================================
inline Standard_Real math_KronrodSingleIntegration::AbsolutError() const
{
StdFail_NotDone_Raise_if(!myIsDone, "math_KronrodSingleIntegration");
return myAbsolutError;
}
//==========================================================================
//function : OrderReached
// Returns the number of Kronrod points for which the result
// is computed.
//==========================================================================
inline Standard_Integer math_KronrodSingleIntegration::OrderReached() const
{
StdFail_NotDone_Raise_if(!myIsDone, "math_KronrodSingleIntegration");
return myNbPntsReached;
}
//==========================================================================
//function : NbIterReached
// Returns the number of iterations that were made to compute result.
//==========================================================================
inline Standard_Integer math_KronrodSingleIntegration::NbIterReached() const
{
StdFail_NotDone_Raise_if(!myIsDone, "math_KronrodSingleIntegration");
return myNbIterReached;
}

563
src/math/math_Matrix.cdl Executable file
View File

@@ -0,0 +1,563 @@
-- File: Matrix.cdl
-- Created: Tue May 7 13:53:36 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
class Matrix from math
---Purpose: This class implements the real matrix abstract data type.
-- Matrixes can have an arbitrary range which must be defined
-- at the declaration and cannot be changed after this declaration
-- math_Matrix(-3,5,2,4); //a vector with range [-3..5, 2..4]
-- Matrix values may be initialized and
-- retrieved using indexes which must lie within the range
-- of definition of the matrix.
-- Matrix objects follow "value semantics", that is, they
-- cannot be shared and are copied through assignment
-- Matrices are copied through assignement:
-- math_Matrix M2(1, 9, 1, 3);
-- ...
-- M2 = M1;
-- M1(1) = 2.0;//the matrix M2 will not be modified.
--
-- The exception RangeError is raised when trying to access
-- outside the range of a matrix :
-- M1(11, 1)=0.0// --> will raise RangeError.
--
-- The exception DimensionError is raised when the dimensions of
-- two matrices or vectors are not compatible.
-- math_Matrix M3(1, 2, 1, 2);
-- M3 = M1; // will raise DimensionError
-- M1.Add(M3) // --> will raise DimensionError.
-- A Matrix can be constructed with a a pointer to "c array".
-- It allows to carry the bounds inside the matrix.
-- Exemple :
-- Standard_Real tab1[10][20];
-- Standard_Real tab2[200];
--
-- math_Matrix A (tab1[0][0], 1, 10, 1, 20);
-- math_Matrix B (tab2[0], 1, 10, 1, 20);
uses Vector from math,
DoubleTabOfReal from math,
OStream from Standard
raises DimensionError from Standard, RangeError from Standard,
DivideByZero from Standard, NotSquare from math,
SingularMatrix from math
is
Create(LowerRow, UpperRow, LowerCol, UpperCol: Integer)
---Purpose: Constructs a non-initialized matrix of range [LowerRow..UpperRow,
-- LowerCol..UpperCol]
-- For the constructed matrix:
-- - LowerRow and UpperRow are the indexes of the
-- lower and upper bounds of a row, and
-- - LowerCol and UpperCol are the indexes of the
-- lower and upper bounds of a column.
returns Matrix
raises RangeError;
Create(LowerRow, UpperRow, LowerCol, UpperCol: Integer;
InitialValue : Real)
---Purpose: constructs a non-initialized matrix of range [LowerRow..UpperRow,
-- LowerCol..UpperCol]
-- whose values are all initialized with the value InitialValue.
returns Matrix
raises RangeError;
Create(Tab : Address;
LowerRow, UpperRow, LowerCol, UpperCol: Integer)
---Purpose: constructs a matrix of range [LowerRow..UpperRow,
-- LowerCol..UpperCol]
-- Sharing data with a "C array" pointed by Tab.
returns Matrix
raises RangeError;
Create(Other: Matrix)
---Purpose: constructs a matrix for copy in initialization.
-- An exception is raised if the matrixes have not the same dimensions.
returns Matrix
raises DimensionError;
--JR/Hp is private;
SetLowerRow(me: in out; LowerRow: Integer)
---Purpose: The new lower row of the matrix is set to <LowerRow>
is static protected;
SetLowerCol(me: in out; LowerCol: Integer)
---Purpose: The new lower column of the matrix is set to the column
-- of range <LowerCol>.
is static protected;
SetLower(me: in out; LowerRow, LowerCol: Integer)
---Purpose: The new lower row of the matrix is set to <LowerRow>
--- and the new lower column of the matrix is set to the column
-- of range <LowerCol>.
---C++: inline
is static protected;
Init(me : in out; InitialValue: Real)
---Purpose:Initialize all the elements of a matrix to InitialValue.
is static;
RowNumber(me)
---Purpose: Returns the number of rows of this matrix.
-- Note that for a matrix A you always have the following relations:
-- - A.RowNumber() = A.UpperRow() - A.LowerRow() + 1
-- - A.ColNumber() = A.UpperCol() - A.LowerCol() + 1
-- - the length of a row of A is equal to the number of columns of A,
-- - the length of a column of A is equal to the number of
-- rows of A.returns the row range of a matrix.
---C++: inline
returns Integer
is static;
ColNumber(me)
---Purpose: Returns the number of rows of this matrix.
-- Note that for a matrix A you always have the following relations:
-- - A.RowNumber() = A.UpperRow() - A.LowerRow() + 1
-- - A.ColNumber() = A.UpperCol() - A.LowerCol() + 1
-- - the length of a row of A is equal to the number of columns of A,
-- - the length of a column of A is equal to the number of
-- rows of A.returns the row range of a matrix.
---C++: inline
returns Integer
is static;
LowerRow(me)
---Purpose: Returns the value of the Lower index of the row
-- range of a matrix.
---C++: inline
returns Integer
is static;
UpperRow(me)
---Purpose: Returns the Upper index of the row range
-- of a matrix.
---C++: inline
returns Integer
is static;
LowerCol(me)
---Purpose: Returns the value of the Lower index of the
-- column range of a matrix.
---C++: inline
returns Integer
is static;
UpperCol(me)
---Purpose: Returns the value of the upper index of the
-- column range of a matrix.
---C++: inline
returns Integer
is static;
Determinant(me)
---Purpose: Computes the determinant of a matrix.
-- An exception is raised if the matrix is not a square matrix.
returns Real
raises NotSquare
is static;
Transpose(me: in out)
---Purpose: Transposes a given matrix.
-- An exception is raised if the matrix is not a square matrix.
raises NotSquare from math
is static;
Invert(me: in out)
---Purpose: Inverts a matrix using Gauss algorithm.
-- Exception NotSquare is raised if the matrix is not square.
-- Exception SingularMatrix is raised if the matrix is singular.
raises NotSquare from math,
SingularMatrix from math
is static;
Multiply(me: in out; Right: Real)
---Purpose: Sets this matrix to the product of the matrix Left, and the matrix Right.
-- Example
-- math_Matrix A (1, 3, 1, 3);
-- math_Matrix B (1, 3, 1, 3);
-- // A = ... , B = ...
-- math_Matrix C (1, 3, 1, 3);
-- C.Multiply(A, B);
-- Exceptions
-- Standard_DimensionError if matrices are of incompatible dimensions, i.e. if:
-- - the number of columns of matrix Left, or the number of
-- rows of matrix TLeft is not equal to the number of rows
-- of matrix Right, or
-- - the number of rows of matrix Left, or the number of
-- columns of matrix TLeft is not equal to the number of
-- rows of this matrix, or
-- - the number of columns of matrix Right is not equal to
-- the number of columns of this matrix.
---C++: alias operator*=
is static;
Multiplied(me; Right: Real)
---Purpose: multiplies all the elements of a matrix by the
-- value <Right>.
---C++: alias operator*
returns Matrix
is static;
TMultiplied(me; Right: Real)
---Purpose: Sets this matrix to the product of the
-- transposed matrix TLeft, and the matrix Right.
-- Example
-- math_Matrix A (1, 3, 1, 3);
-- math_Matrix B (1, 3, 1, 3);
-- // A = ... , B = ...
-- math_Matrix C (1, 3, 1, 3);
-- C.Multiply(A, B);
-- Exceptions
-- Standard_DimensionError if matrices are of incompatible dimensions, i.e. if:
-- - the number of columns of matrix Left, or the number of
-- rows of matrix TLeft is not equal to the number of rows
-- of matrix Right, or
-- - the number of rows of matrix Left, or the number of
-- columns of matrix TLeft is not equal to the number of
-- rows of this matrix, or
-- - the number of columns of matrix Right is not equal to
-- the number of columns of this matrix.
---C++: alias "friend math_Matrix operator *(const Standard_Real Left,const math_Matrix& Right);"
returns Matrix
is static;
Divide(me: in out; Right: Real)
---Purpose: divides all the elements of a matrix by the value <Right>.
-- An exception is raised if <Right> = 0.
---C++: alias operator/=
raises DivideByZero
is static;
Divided(me; Right: Real)
---Purpose: divides all the elements of a matrix by the value <Right>.
-- An exception is raised if <Right> = 0.
---C++: alias operator/
returns Matrix
raises DivideByZero
is static;
Add(me: in out; Right: Matrix)
---Purpose: adds the matrix <Right> to a matrix.
-- An exception is raised if the dimensions are different.
-- Warning
-- In order to save time when copying matrices, it is
-- preferable to use operator += or the function Add
-- whenever possible.
---C++: alias operator+=
raises DimensionError
is static;
Added(me; Right: Matrix)
---Purpose: adds the matrix <Right> to a matrix.
-- An exception is raised if the dimensions are different.
---C++: alias operator+
returns Matrix
raises DimensionError
is static;
Add(me: in out; Left, Right: Matrix)
---Purpose: sets a matrix to the addition of <Left> and <Right>.
-- An exception is raised if the dimensions are different.
raises DimensionError
is static;
Subtract(me: in out; Right: Matrix)
---Purpose: Subtracts the matrix <Right> from <me>.
-- An exception is raised if the dimensions are different.
-- Warning
-- In order to avoid time-consuming copying of matrices, it
-- is preferable to use operator -= or the function
-- Subtract whenever possible.
---C++: alias operator-=
raises DimensionError
is static;
Subtracted(me; Right: Matrix)
---Purpose: Returns the result of the subtraction of <Right> from <me>.
-- An exception is raised if the dimensions are different.
---C++: alias operator-
returns Matrix
raises DimensionError
is static;
Set(me: in out; I1, I2, J1, J2: Integer; M: Matrix)
---Purpose: Sets the values of this matrix,
-- - from index I1 to index I2 on the row dimension, and
-- - from index J1 to index J2 on the column dimension,
-- to those of matrix M.
-- Exceptions
-- Standard_DimensionError if:
-- - I1 is less than the index of the lower row bound of this matrix, or
-- - I2 is greater than the index of the upper row bound of this matrix, or
-- - J1 is less than the index of the lower column bound of this matrix, or
-- - J2 is greater than the index of the upper column bound of this matrix, or
-- - I2 - I1 + 1 is not equal to the number of rows of matrix M, or
-- - J2 - J1 + 1 is not equal to the number of columns of matrix M.
raises DimensionError
is static;
SetRow(me: in out; Row: Integer; V: Vector)
---Purpose: Sets the row of index Row of a matrix to the vector <V>.
-- An exception is raised if the dimensions are different.
-- An exception is raises if <Row> is inferior to the lower
-- row of the matrix or <Row> is superior to the upper row.
raises RangeError, DimensionError
is static;
SetCol(me: in out; Col: Integer; V: Vector)
---Purpose: Sets the column of index Col of a matrix to the vector <V>.
-- An exception is raised if the dimensions are different.
-- An exception is raises if <Col> is inferior to the lower
-- column of the matrix or <Col> is superior to the upper
-- column.
raises RangeError, DimensionError
is static;
SetDiag(me: in out; Value: Real)
---Purpose: Sets the diagonal of a matrix to the value <Value>.
-- An exception is raised if the matrix is not square.
raises NotSquare
is static;
Row(me; Row: Integer)
---Purpose: Returns the row of index Row of a matrix.
returns Vector
is static;
Col(me; Col: Integer)
---Purpose: Returns the column of index <Col> of a matrix.
returns Vector
is static;
SwapRow(me: in out; Row1, Row2: Integer)
---Purpose: Swaps the rows of index Row1 and Row2.
-- An exception is raised if <Row1> or <Row2> is out of range.
raises RangeError
is static;
SwapCol(me: in out; Col1, Col2: Integer)
---Purpose: Swaps the columns of index <Col1> and <Col2>.
-- An exception is raised if <Col1> or <Col2> is out of range.
raises RangeError
is static;
Transposed(me)
---Purpose: Teturns the transposed of a matrix.
-- An exception is raised if the matrix is not a square matrix.
returns Matrix
raises NotSquare
is static;
Inverse(me)
---Purpose: Returns the inverse of a matrix.
-- Exception NotSquare is raised if the matrix is not square.
-- Exception SingularMatrix is raised if the matrix is singular.
returns Matrix
raises NotSquare, SingularMatrix
is static;
TMultiply(me; Right: Matrix)
---Purpose: Returns the product of the transpose of a matrix with
-- the matrix <Right>.
-- An exception is raised if the dimensions are different.
returns Matrix
raises DimensionError
is static;
Multiply(me: in out; Left, Right: Vector)
---Purpose: Computes a matrix as the product of 2 vectors.
-- An exception is raised if the dimensions are different.
-- <me> = <Left> * <Right>.
raises DimensionError
is static;
Multiply(me: in out; Left, Right: Matrix)
---Purpose: Computes a matrix as the product of 2 matrixes.
-- An exception is raised if the dimensions are different.
raises DimensionError
is static;
TMultiply(me: in out; TLeft, Right: Matrix)
---Purpose: Computes a matrix to the product of the transpose of
-- the matrix <TLeft> with the matrix <Right>.
-- An exception is raised if the dimensions are different.
raises DimensionError
is static;
Subtract(me: in out; Left, Right: Matrix)
---Purpose: Sets a matrix to the Subtraction of the matrix <Right>
-- from the matrix <Left>.
-- An exception is raised if the dimensions are different.
raises DimensionError
is static;
Value(me; Row, Col: Integer)
---Purpose: Accesses (in read or write mode) the value of index <Row>
-- and <Col> of a matrix.
-- An exception is raised if <Row> and <Col> are not
-- in the correct range.
---C++: alias operator()
---C++: return &
---C++: inline
returns Real
raises RangeError
is static;
Initialized(me: in out; Other: Matrix)
---Purpose: Matrixes are copied through assignement.
-- An exception is raised if the dimensions are differents.
---C++: alias operator=
---C++: return &
returns Matrix
raises DimensionError
is static;
Multiply(me: in out; Right: Matrix)
---Purpose: Returns the product of 2 matrices.
-- An exception is raised if the dimensions are different.
---C++: alias operator*=
raises DimensionError
is static;
Multiplied(me; Right: Matrix)
---Purpose: Returns the product of 2 matrices.
-- An exception is raised if the dimensions are different.
---C++: alias operator*
returns Matrix
raises DimensionError
is static;
Multiplied(me; Right: Vector)
---Purpose: Returns the product of a matrix by a vector.
-- An exception is raised if the dimensions are different.
---C++: alias operator*
returns Vector
raises DimensionError
is static;
Opposite(me : in out)
---Purpose: Returns the opposite of a matrix.
-- An exception is raised if the dimensions are different.
---C++: alias operator-
returns Matrix
raises DimensionError from Standard
is static;
Dump(me; o: in out OStream)
---Purpose: Prints information on the current state of the object.
-- Is used to redefine the operator <<.
is static;
fields
LowerRowIndex: Integer;
UpperRowIndex: Integer;
LowerColIndex: Integer;
UpperColIndex: Integer;
Array: DoubleTabOfReal;
friends
class Vector from math
end Matrix;

673
src/math/math_Matrix.cxx Executable file
View File

@@ -0,0 +1,673 @@
//static const char* sccsid = "@(#)math_Matrix.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
//#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#define No_Standard_DimensionError
//#endif
#include <math_Matrix.ixx>
#include <math_Vector.hxx>
#include <Standard_DimensionError.hxx>
#include <Standard_DivideByZero.hxx>
#include <Standard_RangeError.hxx>
#include <math_SingularMatrix.hxx>
#include <math_NotSquare.hxx>
#include <math_Gauss.hxx>
void math_Matrix::SetLowerRow(const Standard_Integer LowerRow) {
Array.SetLowerRow(LowerRow);
Standard_Integer Rows = RowNumber();
LowerRowIndex = LowerRow;
UpperRowIndex = LowerRowIndex + Rows - 1;
}
void math_Matrix::SetLowerCol(const Standard_Integer LowerCol) {
Array.SetLowerCol(LowerCol);
Standard_Integer Cols = ColNumber();
LowerColIndex = LowerCol;
UpperColIndex = LowerColIndex + Cols - 1;
}
math_Matrix::math_Matrix (const Standard_Integer LowerRow,
const Standard_Integer UpperRow,
const Standard_Integer LowerCol,
const Standard_Integer UpperCol):
LowerRowIndex(LowerRow),
UpperRowIndex(UpperRow),
LowerColIndex(LowerCol),
UpperColIndex(UpperCol),
Array(LowerRow, UpperRow,
LowerCol, UpperCol)
{
Standard_RangeError_Raise_if((LowerRow > UpperRow) ||
(LowerCol > UpperCol), "");
}
math_Matrix::math_Matrix (const Standard_Integer LowerRow,
const Standard_Integer UpperRow,
const Standard_Integer LowerCol,
const Standard_Integer UpperCol,
const Standard_Real InitialValue):
LowerRowIndex(LowerRow),
UpperRowIndex(UpperRow),
LowerColIndex(LowerCol),
UpperColIndex(UpperCol),
Array(LowerRow, UpperRow,
LowerCol, UpperCol)
{
Standard_RangeError_Raise_if((LowerRow > UpperRow) ||
(LowerCol > UpperCol), "");
Array.Init(InitialValue);
}
math_Matrix::math_Matrix (const Standard_Address Tab,
const Standard_Integer LowerRow,
const Standard_Integer UpperRow,
const Standard_Integer LowerCol,
const Standard_Integer UpperCol) :
LowerRowIndex(LowerRow),
UpperRowIndex(UpperRow),
LowerColIndex(LowerCol),
UpperColIndex(UpperCol),
Array(*((const Standard_Real *)Tab),
LowerRow, UpperRow,
LowerCol, UpperCol)
{
Standard_RangeError_Raise_if((LowerRow > UpperRow) ||
(LowerCol > UpperCol), "");
}
void math_Matrix::Init(const Standard_Real InitialValue)
{
Array.Init(InitialValue);
}
math_Matrix::math_Matrix (const math_Matrix& Other):
LowerRowIndex(Other.LowerRow()),
UpperRowIndex(Other.UpperRow()),
LowerColIndex(Other.LowerCol()),
UpperColIndex(Other.UpperCol()),
Array(Other.Array)
{
}
math_Matrix math_Matrix::Divided (const Standard_Real Right) const
{
Standard_DivideByZero_Raise_if(Abs(Right) <= RealEpsilon(), "");
math_Matrix temp = Multiplied(1./Right);
return temp;
}
Standard_Real math_Matrix::Determinant() const
{
math_Gauss Sol(*this);
if(Sol.IsDone()) {
return Sol.Determinant();
}
else {
return 0.0;
}
}
void math_Matrix::Transpose()
{
math_NotSquare_Raise_if(RowNumber() != ColNumber(), "");
Standard_Integer Row = LowerRowIndex;
Standard_Integer Col = LowerColIndex;
SetLowerCol(LowerRowIndex);
Standard_Real Temp;
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
for(Standard_Integer J = I; J <= UpperColIndex; J++) {
Temp = Array(I, J);
Array(I, J) = Array(J, I);
Array(J, I) = Temp;
}
}
SetLowerRow(Col);
SetLowerCol(Row);
}
math_Matrix math_Matrix::Transposed() const
{
math_Matrix Result(LowerColIndex, UpperColIndex,
LowerRowIndex, UpperRowIndex);
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Result.Array(J, I) = Array(I, J);
}
}
return Result;
}
void math_Matrix::Invert()
{
math_NotSquare_Raise_if(RowNumber() != ColNumber(), "");
math_Gauss Sol(*this);
if(Sol.IsDone()) {
Sol.Invert(*this);
}
else {
math_SingularMatrix::Raise(); // SingularMatrix Exception;
}
}
math_Matrix math_Matrix::Inverse() const
{
math_Matrix Result = *this;
Result.Invert();
return Result;
}
void math_Matrix::Multiply (const Standard_Real Right)
{
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Array(I, J) = Array(I, J) * Right;
}
}
}
math_Matrix math_Matrix::Multiplied (const Standard_Real Right) const
{
math_Matrix Result(LowerRowIndex, UpperRowIndex,
LowerColIndex, UpperColIndex);
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Result.Array(I, J) = Array(I, J) * Right;
}
}
return Result;
}
math_Matrix math_Matrix::TMultiplied (const Standard_Real Right) const
{
math_Matrix Result(LowerRowIndex, UpperRowIndex,
LowerColIndex, UpperColIndex);
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Result.Array(I, J) = Array(I, J) * Right;
}
}
return Result;
}
void math_Matrix::Divide (const Standard_Real Right)
{
Standard_DivideByZero_Raise_if(Abs(Right) <= RealEpsilon(), "");
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Array(I, J) = Array(I, J) / Right;
}
}
}
void math_Matrix::Add (const math_Matrix& Right)
{
Standard_DimensionError_Raise_if((RowNumber() != Right.RowNumber()) ||
(ColNumber() != Right.ColNumber()),
"");
Standard_Integer I2 = Right.LowerRowIndex;
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
Standard_Integer J2 = Right.LowerColIndex;
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Array(I, J) = Array(I, J) + Right.Array(I2, J2);
J2++;
}
I2++;
}
}
void math_Matrix::Subtract (const math_Matrix& Right)
{
Standard_DimensionError_Raise_if((RowNumber() != Right.RowNumber()) ||
(ColNumber() != Right.ColNumber()),
"");
Standard_Integer I2 = Right.LowerRowIndex;
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
Standard_Integer J2 = Right.LowerColIndex;
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Array(I, J) = Array(I, J) - Right.Array(I2, J2);
J2++;
}
I2++;
}
}
void math_Matrix::Set(const Standard_Integer I1,const Standard_Integer I2,
const Standard_Integer J1,const Standard_Integer J2,
const math_Matrix& M)
{
Standard_DimensionError_Raise_if((I1 < LowerRowIndex) ||
(I2 > UpperRowIndex) ||
(J1 < LowerColIndex) ||
(J2 > UpperColIndex) ||
(I1 > I2) || (J1 > J2) ||
(I2-I1+1 != M.RowNumber()) ||
(J2-J1+1 != M.ColNumber()), "");
Standard_Integer II = M.LowerRow();
for(Standard_Integer I = I1; I <= I2; I++) {
Standard_Integer JJ = M.LowerCol();
for(Standard_Integer J = J1; J <= J2; J++) {
Array(I, J) = M.Array(II, JJ);
JJ++;
}
II++;
}
}
void math_Matrix::SetRow (const Standard_Integer Row,
const math_Vector& V)
{
Standard_RangeError_Raise_if((Row < LowerRowIndex) ||
(Row > UpperRowIndex) , "");
Standard_DimensionError_Raise_if(ColNumber() != V.Length(), "");
Standard_Integer I = V.LowerIndex;
for(Standard_Integer Index = LowerColIndex; Index <= UpperColIndex; Index++) {
Array(Row, Index) = V.Array(I);
I++;
}
}
void math_Matrix::SetCol (const Standard_Integer Col,
const math_Vector& V)
{
Standard_RangeError_Raise_if((Col < LowerColIndex) ||
(Col > UpperColIndex) , "");
Standard_DimensionError_Raise_if(RowNumber() != V.Length(), "");
Standard_Integer I = V.LowerIndex;
for(Standard_Integer Index = LowerRowIndex; Index <= UpperRowIndex; Index++) {
Array(Index, Col) = V.Array(I);
I++;
}
}
void math_Matrix::SetDiag(const Standard_Real Value)
{
math_NotSquare_Raise_if(RowNumber() != ColNumber(), "");
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
Array(I, I) = Value;
}
}
math_Vector math_Matrix::Row (const Standard_Integer Row) const
{
math_Vector Result(LowerColIndex, UpperColIndex);
for(Standard_Integer Index = LowerColIndex; Index <= UpperColIndex; Index++) {
Result.Array(Index) = Array(Row, Index);
}
return Result;
}
math_Vector math_Matrix::Col (const Standard_Integer Col) const
{
math_Vector Result(LowerRowIndex, UpperRowIndex);
for(Standard_Integer Index = LowerRowIndex; Index <= UpperRowIndex; Index++) {
Result.Array(Index) = Array(Index, Col);
}
return Result;
}
void math_Matrix::SwapRow(const Standard_Integer Row1,
const Standard_Integer Row2)
{
Standard_RangeError_Raise_if((Row1 < LowerRowIndex) ||
(Row1 > UpperRowIndex) ||
(Row2 < LowerRowIndex) ||
(Row2 > UpperRowIndex), "");
math_Vector V1 = Row(Row1);
math_Vector V2 = Row(Row2);
SetRow(Row1,V2);
SetRow(Row2,V1);
}
void math_Matrix::SwapCol(const Standard_Integer Col1,
const Standard_Integer Col2)
{
Standard_RangeError_Raise_if((Col1 < LowerColIndex) ||
(Col1 > UpperColIndex) ||
(Col2 < LowerColIndex) ||
(Col2 > UpperColIndex), "");
math_Vector V1 = Col(Col1);
math_Vector V2 = Col(Col2);
SetCol(Col1,V2);
SetCol(Col2,V1);
}
math_Matrix math_Matrix::Multiplied (const math_Matrix& Right) const
{
Standard_DimensionError_Raise_if(ColNumber() != Right.RowNumber(), "");
math_Matrix Result(LowerRowIndex, UpperRowIndex,
Right.LowerColIndex, Right.UpperColIndex);
Standard_Real Som;
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
for(Standard_Integer J2 = Right.LowerColIndex; J2 <= Right.UpperColIndex; J2++) {
Som = 0.0;
Standard_Integer I2 = Right.LowerRowIndex;
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Som = Som + Array(I, J) * Right.Array(I2, J2);
I2++;
}
Result.Array(I, J2) = Som;
}
}
return Result;
}
math_Matrix math_Matrix::TMultiply (const math_Matrix& Right) const
{
Standard_DimensionError_Raise_if(RowNumber() != Right.RowNumber(), "");
math_Matrix Result(LowerColIndex, UpperColIndex,
Right.LowerColIndex, Right.UpperColIndex);
Standard_Real Som;
for(Standard_Integer I = LowerColIndex; I <= UpperColIndex; I++) {
for(Standard_Integer J2 = Right.LowerColIndex; J2 <= Right.UpperColIndex; J2++) {
Som = 0.0;
Standard_Integer I2 = Right.LowerRowIndex;
for(Standard_Integer J = LowerRowIndex; J <= UpperRowIndex; J++) {
Som = Som + Array(J, I) * Right.Array(I2, J2);
I2++;
}
Result.Array(I, J2) = Som;
}
}
return Result;
}
math_Matrix math_Matrix::Added (const math_Matrix& Right) const
{
Standard_DimensionError_Raise_if((RowNumber() != Right.RowNumber()) ||
(ColNumber() != Right.ColNumber()),
"");
math_Matrix Result(LowerRowIndex, UpperRowIndex,
LowerColIndex, UpperColIndex);
Standard_Integer I2 = Right.LowerRowIndex;
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
Standard_Integer J2 = Right.LowerColIndex;
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Result.Array(I, J) = Array(I, J) + Right.Array(I2, J2);
J2++;
}
I2++;
}
return Result;
}
math_Matrix math_Matrix::Opposite ()
{
math_Matrix Result(LowerRowIndex, UpperRowIndex,
LowerColIndex, UpperColIndex);
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Result.Array(I, J) = - Array(I, J);
}
}
return Result;
}
math_Matrix math_Matrix::Subtracted (const math_Matrix& Right) const
{
Standard_DimensionError_Raise_if((RowNumber() != Right.RowNumber()) ||
(ColNumber() != Right.ColNumber()),
"");
math_Matrix Result(LowerRowIndex, UpperRowIndex,
LowerColIndex, UpperColIndex);
Standard_Integer I2 = Right.LowerRowIndex;
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
Standard_Integer J2 = Right.LowerColIndex;
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Result.Array(I, J) = Array(I, J) - Right.Array(I2, J2);
J2++;
}
I2++;
}
return Result;
}
void math_Matrix::Multiply(const math_Vector& Left,
const math_Vector& Right)
{
Standard_DimensionError_Raise_if((RowNumber() != Left.Length()) ||
(ColNumber() != Right.Length()),
"");
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Array(I, J) = Left.Array(I) * Right.Array(J);
}
}
}
void math_Matrix::Multiply(const math_Matrix& Left,
const math_Matrix& Right)
{
Standard_DimensionError_Raise_if((Left.ColNumber() != Right.RowNumber()) ||
(RowNumber() != Left.RowNumber()) ||
(ColNumber() != Right.ColNumber()),
"");
Standard_Real Som;
Standard_Integer I1 = Left.LowerRowIndex;
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
Standard_Integer J2 = Right.LowerColIndex;
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Som = 0.0;
Standard_Integer J1 = Left.LowerColIndex;
Standard_Integer I2 = Right.LowerRowIndex;
for(Standard_Integer K = Left.LowerColIndex; K <= Left.UpperColIndex; K++) {
Som = Som + Left.Array(I1, J1) * Right.Array(I2, J2);
J1++;
I2++;
}
Array(I, J) = Som;
J2++;
}
I1++;
}
}
void math_Matrix::TMultiply(const math_Matrix& TLeft,
const math_Matrix& Right)
{
Standard_DimensionError_Raise_if((TLeft.RowNumber() != Right.RowNumber()) ||
(RowNumber() != TLeft.ColNumber()) ||
(ColNumber() != Right.ColNumber()),
"");
Standard_Real Som;
Standard_Integer I1 = TLeft.LowerColIndex;
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
Standard_Integer J2 = Right.LowerColIndex;
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Som = 0.0;
Standard_Integer J1 = TLeft.LowerRowIndex;
Standard_Integer I2 = Right.LowerRowIndex;
for(Standard_Integer K = TLeft.LowerRowIndex; K <= TLeft.UpperRowIndex; K++) {
Som = Som + TLeft.Array(J1, I1) * Right.Array(I2, J2);
J1++;
I2++;
}
Array(I, J) = Som;
J2++;
}
I1++;
}
}
void math_Matrix::Add (const math_Matrix& Left,
const math_Matrix& Right)
{
Standard_DimensionError_Raise_if((RowNumber() != Right.RowNumber()) ||
(ColNumber() != Right.ColNumber()) ||
(Right.RowNumber() != Left.RowNumber()) ||
(Right.ColNumber() != Left.ColNumber()),
"");
Standard_Integer I1 = Left.LowerRowIndex;
Standard_Integer I2 = Right.LowerRowIndex;
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
Standard_Integer J1 = Left.LowerColIndex;
Standard_Integer J2 = Right.LowerColIndex;
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Array(I, J) = Left.Array(I1, J1) + Right.Array(I2, J2);
J1++;
J2++;
}
I1++;
I2++;
}
}
void math_Matrix::Subtract(const math_Matrix& Left,
const math_Matrix& Right)
{
Standard_DimensionError_Raise_if((RowNumber() != Right.RowNumber()) ||
(ColNumber() != Right.ColNumber()) ||
(Right.RowNumber() != Left.RowNumber()) ||
(Right.ColNumber() != Left.ColNumber()),
"");
Standard_Integer I1 = Left.LowerRowIndex;
Standard_Integer I2 = Right.LowerRowIndex;
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
Standard_Integer J1 = Left.LowerColIndex;
Standard_Integer J2 = Right.LowerColIndex;
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Array(I, J) = Left.Array(I1, J1) - Right.Array(I2, J2);
J1++;
J2++;
}
I1++;
I2++;
}
}
void math_Matrix::Multiply(const math_Matrix& Right)
{
Standard_DimensionError_Raise_if(ColNumber() != Right.RowNumber(), "");
Standard_Real Som;
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
for(Standard_Integer J2 = Right.LowerColIndex; J2 <= Right.UpperColIndex; J2++) {
Som = 0.0;
Standard_Integer I2 = Right.LowerRowIndex;
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Som = Som + Array(I, J) * Right.Array(I2, J2);
I2++;
}
Array(I, J2) = Som;
}
}
}
math_Vector math_Matrix::Multiplied(const math_Vector& Right)const
{
Standard_DimensionError_Raise_if(ColNumber() != Right.Length(), "");
math_Vector Result(LowerRowIndex, UpperRowIndex);
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
Result.Array(I) = 0.0;
Standard_Integer II = Right.LowerIndex;
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
Result.Array(I) = Result.Array(I) + Array(I, J) * Right.Array(II);
II++;
}
}
return Result;
}
math_Matrix& math_Matrix::Initialized(const math_Matrix& Other)
{
Standard_DimensionError_Raise_if((RowNumber() != Other.RowNumber()) ||
(ColNumber() != Other.ColNumber()), "");
(Other.Array).Copy(Array);
return *this;
}
void math_Matrix::Dump(Standard_OStream& o)const
{
o << "math_Matrix of RowNumber = " << RowNumber();
o << " and ColNumber = " << ColNumber() << "\n";
for(Standard_Integer I = LowerRowIndex; I <= UpperRowIndex; I++) {
for(Standard_Integer J = LowerColIndex; J <= UpperColIndex; J++) {
o << "math_Matrix ( " << I << ", " << J << " ) = ";
o << Array(I, J) << "\n";
}
}
}

68
src/math/math_Matrix.lxx Executable file
View File

@@ -0,0 +1,68 @@
// File math_Matrix.lxx
// lpa le 29/10/91
#include <Standard_DimensionError.hxx>
#include <math_Vector.hxx>
inline Standard_OStream& operator<<(Standard_OStream& o,
const math_Matrix& mat)
{
mat.Dump(o);
return o;
}
inline math_Matrix operator* (const Standard_Real Left,
const math_Matrix& Right)
{
return Right.Multiplied(Left);
}
inline Standard_Real& math_Matrix::Value(const Standard_Integer Row,
const Standard_Integer Col)const
{
Standard_RangeError_Raise_if(((Row < LowerRowIndex) ||
(Row > UpperRowIndex) ||
(Col < LowerColIndex) ||
(Col > UpperColIndex)), " ");
return Array(Row, Col);
}
inline Standard_Integer math_Matrix::RowNumber() const
{ return UpperRowIndex - LowerRowIndex + 1; }
// returns the row range of a matrix.
inline Standard_Integer math_Matrix::ColNumber() const
{ return UpperColIndex - LowerColIndex + 1; }
// returns the column range of a matrix.
inline Standard_Integer math_Matrix::LowerRow() const { return LowerRowIndex; }
// returns the value of the Lower index of the row range of a matrix.
inline Standard_Integer math_Matrix::UpperRow () const { return UpperRowIndex; }
// returns the value of the Upper index of the row range of a matrix.
inline Standard_Integer math_Matrix::LowerCol() const { return LowerColIndex; }
// returns the value of the Lower index of the column range of a matrix.
inline Standard_Integer math_Matrix::UpperCol() const { return UpperColIndex; }
// returns the value of the Upper index of the column range of a matrix.
inline void math_Matrix::SetLower (const Standard_Integer LowerRow,
const Standard_Integer LowerCol)
{
SetLowerRow(LowerRow);
SetLowerCol(LowerCol);
}

10
src/math/math_Memory.cxx Executable file
View File

@@ -0,0 +1,10 @@
//static const char* sccsid = "@(#)math_Memory.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
#include <math_Memory.hxx>
void *reverse_move(void *s1, void *s2, int size) {
for(int i = size - 1; i >= 0; i--) {
*((char *)s1 + i) = *((char *)s2 + i);
}
return s1;
}

26
src/math/math_Memory.hxx Executable file
View File

@@ -0,0 +1,26 @@
#ifndef math_Memory_HeaderFile
#define math_Memory_HeaderFile
#include <string.h>
// uniquement parce que memmove n'existe pas sur SUN
#ifndef WNT
void *reverse_move(void *s1, void *s2, int size);
inline void *memmove(void *s1, void *s2, int size) {
/*
void *result;
if(s2 < s1) {
result = reverse_move(s1, s2, size);
}
else {
result = memcpy(s1, s2, size);
}
return result;
*/
return memcpy(s1, s2, size);
}
#endif
#endif

View File

@@ -0,0 +1,53 @@
-- File: MultipleVarFunction.cdl
-- Created: Mon May 13 15:05:02 1991
-- Author: Laurent Painnot
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
deferred class MultipleVarFunction from math
---Purpose:
-- Describes the virtual functions associated with a multiple variable function.
uses Vector from math
is
NbVariables(me)
---Purpose:
-- Returns the number of variables of the function
returns Integer
is deferred;
Value(me: in out; X: Vector; F: out Real)
---Purpose: Computes the values of the Functions <F> for the
-- variable <X>.
-- returns True if the computation was done successfully,
-- otherwise false.
returns Boolean
is deferred;
GetStateNumber(me: in out)
---Purpose: return the state of the function corresponding to the latestt
-- call of any methods associated to the function. This
-- function is called by each of the algorithms described
-- later which define the function Integer
-- Algorithm::StateNumber(). The algorithm has the
-- responsibility to call this function when it has found
-- a solution (i.e. a root or a minimum) and has to maintain
-- the association between the solution found and this
-- StateNumber.
-- Byu default, this method returns 0 (which means for the
-- algorithm: no state has been saved). It is the
-- responsibility of the programmer to decide if he needs
-- to save the current state of the function and to return
-- an Integer that allows retrieval of the state.
returns Integer
is virtual;
end MultipleVarFunction;

View File

@@ -0,0 +1,5 @@
//static const char* sccsid = "@(#)math_MultipleVarFunction.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
#include <Standard_Integer.hxx>
#include <math_MultipleVarFunction.ixx>
Standard_Integer math_MultipleVarFunction::GetStateNumber() { return 0; }

View File

@@ -0,0 +1,57 @@
-- File: MultipleVarFunctionWithGradient.cdl
-- Created: Mon May 13 15:11:12 1991
-- Author: Laurent PAINNOT
-- <lpa@topsn3>
---Copyright: Matra Datavision 1991, 1992
deferred class MultipleVarFunctionWithGradient from math
inherits MultipleVarFunction
---Purpose:
-- The abstract class MultipleVarFunctionWithGradient
-- describes the virtual functions associated with a multiple variable function.
uses Vector from math
is
Delete(me:out) is virtual;
---C++: alias "Standard_EXPORT virtual ~math_MultipleVarFunctionWithGradient(){Delete();}"
NbVariables(me)
---Purpose: Returns the number of variables of the function.
returns Integer
is deferred;
Value(me: in out; X: Vector; F: out Real)
---Purpose: Computes the values of the Functions <F> for the variable <X>.
-- Returns True if the computation was done successfully,
-- False otherwise.
returns Boolean
is deferred;
Gradient(me: in out; X: Vector; G: out Vector)
---Purpose: Computes the gradient <G> of the functions for the variable <X>.
-- Returns True if the computation was done successfully,
-- False otherwise.
returns Boolean
is deferred;
Values(me: in out; X: Vector; F: out Real; G: out Vector)
---Purpose: computes the value <F> and the gradient <G> of the
-- functions for the variable <X>.
-- Returns True if the computation was done successfully,
-- False otherwise.
returns Boolean
is deferred;
end MultipleVarFunctionWithGradient;

View File

@@ -0,0 +1,5 @@
//static const char* sccsid = "@(#)math_MultipleVarFunctionWithGradient.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
#include <math_MultipleVarFunctionWithGradient.ixx>
void math_MultipleVarFunctionWithGradient::Delete()
{}

Some files were not shown because too many files have changed in this diff Show More