6 using namespace mathfce;
11 elm =
new double[ nc * nr ];
17 elm =
new double[ nc * nr ];
24 elm =
new double[nc*nr];
25 memcpy(elm,x.
elm,nc*nr*
sizeof(
double));
34 elm =
new double[size];
40 elm =
new double[size];
41 memcpy(elm,x.
elm,size*
sizeof(
double));
49 for (
int i = 1; i <= M.
nr; i++) {
50 for (
int j = 1; j <= M.
nc; j++) {
51 stream << M.
Get(i, j) <<
" ";
59 for (
int i = 1; i <= V.
size; i++) {
60 stream << V.
elm[ i - 1 ] <<
"\n";
67 THROW( ExcAssertMsg() << EI_Message(
"Number of the row is greater than number of rows in the matrix.") );
69 THROW( ExcAssertMsg() << EI_Message(
"Number of the column is greater than number of columns in the matrix.") );
70 elm[ (row - 1) * nc + col - 1 ] = value;
76 THROW( ExcAssertMsg() << EI_Message(
"Number of the row is greater than number of rows in the matrix.") );
78 THROW( ExcAssertMsg() << EI_Message(
"Number of the column is greater than number of columns in the matrix.") );
79 return elm[ (row - 1) * nc + col - 1 ];
83 if (r1 > nr || r2 > nr) {
84 THROW( ExcAssertMsg() << EI_Message(
"Number of the row is greater than number of rows in the matrix.") );
87 for (
int i = 1; i <= nc; i++) {
88 double tmp = Get(r1, i);
89 Set(r1, i, Get(r2, i));
97 if (i1 > size || i2 > size) {
98 THROW( ExcAssertMsg() << EI_Message(
"Number of the element is greater than size of the vector.") );
101 double tmp = elm[ i1 - 1 ];
102 elm[ i1 - 1 ] = elm[ i2 - 1 ];
110 THROW( ExcAssertMsg() << EI_Message(
"Number of the element is greater than size of the vector.") );
119 THROW( ExcAssertMsg() << EI_Message(
"Number of the element is greater than size of the vector.") );
120 elm[ i - 1 ] = value;
136 for (
int i = 1; i < M.
NRows(); i++) {
137 double tmp = fabs(M.
Get(i, i));
139 for (
int j = i + 1; j <= M.
NRows(); j++)
140 if (fabs(M.
Get(j, i)) > tmp) {
141 tmp = fabs(M.
Get(j, i));
153 for (
int j = i + 1; j <= M.
NRows(); j++) {
154 tmp = M.
Get(j, i) / M.
Get(i, i);
155 for (
int k = i; k <= M.
NCols(); k++) {
156 M.
Set(j, k, M.
Get(j, k) - tmp * M.
Get(i, k));
162 for (
int i = M.
NRows(); i >= 1; i--) {
163 double tmp = b.
Get(i);
165 for (
int k = i + 1; k <= M.
NCols(); k++) {
166 tmp -= M.
Get(i, k) * X->
Get(k);
177 X->
Set(i, tmp / M.
Get(i, i));
TNSolutions Gauss(const TMatrix &A, TMVector *X, const TMVector &B)
double Get(int, int) const
void SwapElements(int, int)
void Set(int, int, double)
std::ostream & operator<<(std::ostream &stream, const TMatrix &M)
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.