#include <linalg.h>
|
static void | SymetricToTridiag (TFltVV &a, int n, TFltV &d, TFltV &e) |
|
static void | EigSymmetricTridiag (TFltV &d, TFltV &e, int n, TFltVV &z) |
|
static void | CholeskyDecomposition (TFltVV &A, TFltV &p) |
|
static void | CholeskySolve (const TFltVV &A, const TFltV &p, const TFltV &b, TFltV &x) |
|
static void | SolveSymetricSystem (TFltVV &A, const TFltV &b, TFltV &x) |
|
static void | InverseSubstitute (TFltVV &A, const TFltV &p) |
|
static void | InverseSymetric (TFltVV &A) |
|
static void | InverseTriagonal (TFltVV &A) |
|
static void | LUDecomposition (TFltVV &A, TIntV &indx, double &d) |
|
static void | LUSolve (const TFltVV &A, const TIntV &indx, TFltV &b) |
|
static void | SolveLinearSystem (TFltVV &A, const TFltV &b, TFltV &x) |
|
|
static double | sqr (double a) |
|
static double | sign (double a, double b) |
|
static double | pythag (double a, double b) |
|
static void | nrerror (const TStr &error_text) |
|
Definition at line 300 of file linalg.h.
void TNumericalStuff::CholeskyDecomposition |
( |
TFltVV & |
A, |
|
|
TFltV & |
p |
|
) |
| |
|
static |
Definition at line 797 of file linalg.cpp.
805 for (sum=A(i-1,j-1),k=i-1;k>=1;k--) sum -= A(i-1,k-1)*A(j-1,k-1);
810 }
else A(j-1,i-1)=sum/p[i-1];
static void nrerror(const TStr &error_text)
void Reserve(const TSizeTy &_MxVals)
Reserves enough memory for the vector to store _MxVals elements.
Definition at line 815 of file linalg.cpp.
824 for (sum=b[i-1],k=i-1;k>=1;k--)
825 sum -= A(i-1,k-1)*x[k-1];
831 for (sum=x[i-1],k=i+1;k<=n;k++)
832 sum -= A(k-1,i-1)*x[k-1];
void Reserve(const TSizeTy &_MxVals)
Reserves enough memory for the vector to store _MxVals elements.
void TNumericalStuff::EigSymmetricTridiag |
( |
TFltV & |
d, |
|
|
TFltV & |
e, |
|
|
int |
n, |
|
|
TFltVV & |
z |
|
) |
| |
|
static |
Definition at line 740 of file linalg.cpp.
742 double s,r,p,g,f,dd,c,b;
744 for (i=2;i<=n;i++) e[i-1]=e[i];
750 for (m=l;m<=n-1;m++) {
752 if ((
double)(
TFlt::Abs(e[m])+dd) == dd)
break;
755 if (iter++ == 60)
nrerror(
"Too many iterations in EigSymmetricTridiag");
757 g=(d[l+1]-d[l])/(2.0*e[l]);
760 g=d[m]-d[l]+e[l]/(g+
sign(r,g));
765 for (i=m-1;i>=l;i--) {
778 r=(d[i]-g)*s+2.0*c*b;
784 z(k,i)=s*z(k,i-1)+c*f;
785 z(k,i-1)=c*z(k,i-1)-s*f;
788 if (r == 0.0 && i >= l)
continue;
static void nrerror(const TStr &error_text)
static double Abs(const double &Flt)
static double pythag(double a, double b)
static double sign(double a, double b)
void TNumericalStuff::InverseSubstitute |
( |
TFltVV & |
A, |
|
|
const TFltV & |
p |
|
) |
| |
|
static |
Definition at line 843 of file linalg.cpp.
847 int i, j, k;
double sum;
848 for (i = 0; i < n; i++) {
851 for (j = 0; j < i; j++) x[j] = 0.0;
855 for (j = i+1; j < n; j++) {
856 for (sum = 0.0, k = i; k < j; k++)
857 sum -= A(j,k) * x[k];
862 for (j = n-1; j >= i; j--) {
863 for (sum = x[j], k = j+1; k < n; k++)
867 for (
int j = i; j < n; j++) A(i,j) = x[j];
void TNumericalStuff::InverseSymetric |
( |
TFltVV & |
A | ) |
|
|
static |
Definition at line 872 of file linalg.cpp.
static void CholeskyDecomposition(TFltVV &A, TFltV &p)
static void InverseSubstitute(TFltVV &A, const TFltV &p)
void TNumericalStuff::InverseTriagonal |
( |
TFltVV & |
A | ) |
|
|
static |
Definition at line 881 of file linalg.cpp.
885 int i, j, k;
double sum;
887 for (i = 0; i < n; i++) {
889 for (j = i+1; j < n; j++)
893 for (i = 0; i < n; i++) {
896 for (j = n-1; j > i; j--) x[j] = 0.0;
900 for (j = i-1; j >= 0; j--) {
901 for (sum = 0.0, k = i; k > j; k--)
902 sum -= A(k,j) * x[k];
905 for (
int j = 0; j <= i; j++) A(j,i) = x[j];
void TNumericalStuff::LUDecomposition |
( |
TFltVV & |
A, |
|
|
TIntV & |
indx, |
|
|
double & |
d |
|
) |
| |
|
static |
Definition at line 909 of file linalg.cpp.
913 int i=0,imax=0,j=0,k=0;
914 double big,dum,sum,temp;
922 if ((temp=
TFlt::Abs(A(i-1,j-1))) > big) big=temp;
923 if (big == 0.0)
nrerror(
"Singular matrix in routine LUDecomposition");
930 for (k=1;k<i;k++) sum -= A(i-1,k-1)*A(k-1,j-1);
937 sum -= A(i-1,k-1)*A(k-1,j-1);
941 if ((dum=vv[i-1] *
TFlt::Abs(sum)) >= big) {
952 A(imax-1,k-1)=A(j-1,k-1);
964 if (A(j-1,j-1) == 0.0) A(j-1,j-1)=1e-20;
968 dum=1.0/(A(j-1,j-1));
969 for (i=j+1;i<=n;i++) A(i-1,j-1) *= dum;
static void nrerror(const TStr &error_text)
static double Abs(const double &Flt)
void Reserve(const TSizeTy &_MxVals)
Reserves enough memory for the vector to store _MxVals elements.
void TNumericalStuff::LUSolve |
( |
const TFltVV & |
A, |
|
|
const TIntV & |
indx, |
|
|
TFltV & |
b |
|
) |
| |
|
static |
Definition at line 974 of file linalg.cpp.
984 for (j=ii;j<=i-1;j++) sum -= A(i-1,j-1)*b[j-1];
985 else if (sum) ii=i;b[i-1]=sum;
989 for (j=i+1;j<=n;j++) sum -= A(i-1,j-1)*b[j-1];
990 b[i-1]=sum/A(i-1,i-1);
void TNumericalStuff::nrerror |
( |
const TStr & |
error_text | ) |
|
|
staticprivate |
Definition at line 655 of file linalg.cpp.
656 printf(
"NR_ERROR: %s", error_text.
CStr());
double TNumericalStuff::pythag |
( |
double |
a, |
|
|
double |
b |
|
) |
| |
|
staticprivate |
Definition at line 660 of file linalg.cpp.
661 double absa = fabs(a), absb = fabs(b);
663 return absa*sqrt(1.0+
sqr(absb/absa));
665 return (absb == 0.0 ? 0.0 : absb*sqrt(1.0+
sqr(absa/absb)));
static double sqr(double a)
double TNumericalStuff::sign |
( |
double |
a, |
|
|
double |
b |
|
) |
| |
|
staticprivate |
Definition at line 651 of file linalg.cpp.
652 return b >= 0.0 ? fabs(a) : -fabs(a);
void TNumericalStuff::SolveLinearSystem |
( |
TFltVV & |
A, |
|
|
const TFltV & |
b, |
|
|
TFltV & |
x |
|
) |
| |
|
static |
Definition at line 994 of file linalg.cpp.
995 TIntV indx;
double d;
static void LUSolve(const TFltVV &A, const TIntV &indx, TFltV &b)
static void LUDecomposition(TFltVV &A, TIntV &indx, double &d)
void TNumericalStuff::SolveSymetricSystem |
( |
TFltVV & |
A, |
|
|
const TFltV & |
b, |
|
|
TFltV & |
x |
|
) |
| |
|
static |
Definition at line 837 of file linalg.cpp.
static void CholeskyDecomposition(TFltVV &A, TFltV &p)
static void CholeskySolve(const TFltVV &A, const TFltV &p, const TFltV &b, TFltV &x)
double TNumericalStuff::sqr |
( |
double |
a | ) |
|
|
staticprivate |
Definition at line 647 of file linalg.cpp.
648 return a == 0.0 ? 0.0 : a*a;
void TNumericalStuff::SymetricToTridiag |
( |
TFltVV & |
a, |
|
|
int |
n, |
|
|
TFltV & |
d, |
|
|
TFltV & |
e |
|
) |
| |
|
static |
Definition at line 668 of file linalg.cpp.
670 double scale,hh,h,g,f;
676 scale += fabs(a(i-1,k-1).Val);
682 h += a(i-1,k-1)*a(i-1,k-1);
685 g=(f >= 0.0 ? -sqrt(h) : sqrt(h));
693 a(j-1,i-1)=a(i-1,j-1)/h;
696 g += a(j-1,k-1)*a(i-1,k-1);
698 g += a(k-1,j-1)*a(i-1,k-1);
700 f += e[j]*a(i-1,j-1);
707 a(j-1,k-1) -= (f*e[k]+g*a(i-1,k-1));
708 Assert(_isnan(static_cast<double>(a(j-1,k-1))) == 0);
727 g += a(i-1,k-1)*a(k-1,j-1);
729 a(k-1,j-1) -= g*a(k-1,i-1);
730 Assert(_isnan(static_cast<double>(a(k-1,j-1))) == 0);
736 for (j=1;j<=l;j++) a(j-1,i-1)=a(i-1,j-1)=0.0;
#define IAssertR(Cond, Reason)
The documentation for this class was generated from the following files: