19 ofs << std::fixed << std::setprecision(2);
31 Matrix left{ { { 3, -0.1, -0.2 },
33 { 0.3, -0.2, 10 } } };
36 Vector right{ 7.85, -19.3, 71.4 };
39 LU lusolver{ left, right };
41 const char *sep =
"---------------------\n";
43 auto mupper = lusolver.upper_matrix();
44 auto mlower = lusolver.lower_matrix();
45 auto pmatrix = lusolver.permutation_matrix();
46 auto pdotleft = dot(pmatrix, left);
47 auto ldotu = dot(lusolver.lower_matrix(), lusolver.upper_matrix());
50 ofs << left << sep << right << sep << lusolver.solution();
51 ofs << sep << lusolver.get_left();
52 ofs << sep << mupper << sep << mlower << sep << pmatrix;
53 ofs << sep << pdotleft << sep << ldotu;
61 auto cramer_i = [](
size_t i,
const Matrix &m,
const Vector &v) {
75 Matrix left{ { { 3, -0.1, -0.2 },
77 { 0.3, -0.2, 10 } } };
78 Vector right{ 7.85, -19.3, 71.4 };
81 const size_t N = right.size();
83 for (
size_t i = 0; i <
N; i++) {
84 solution[i] = cramer_i(i, left, right);
86 const char *sep =
"---------------------\n";
88 ofs << sep << left << sep << right << sep << solution;
99 Matrix left{ { { 3, -0.1, -0.2 },
101 { 0.3, -0.2, 10 } } };
104 Vector right{ 7.85, -19.3, 71.4 };
110 Vector solution = dot(leftinverse, right);
112 const char *sep =
"---------------------\n";
114 ofs << sep << left << sep << right;
115 ofs << sep << leftinverse << sep << solution;
117 auto m = dot(leftinverse, left);
118 ofs << sep << std::endl << m;
128 double a_data[] = { 0.18, 0.60, 0.57, 0.96,
129 0.41, 0.24, 0.99, 0.58,
130 0.14, 0.30, 0.97, 0.66,
131 0.51, 0.13, 0.19, 0.85 };
134 double b_data[] = { 1.0, 2.0, 3.0, 4.0 };
138 gsl_matrix_view m = gsl_matrix_view_array(a_data, 4, 4);
142 gsl_vector_view b = gsl_vector_view_array(b_data, 4);
145 gsl_vector *x = gsl_vector_alloc(4);
148 gsl_permutation *p = gsl_permutation_alloc(4);
154 gsl_linalg_LU_decomp(&m.matrix, p, &s);
156 gsl_linalg_LU_solve(&m.matrix, p, &b.vector, x);
159 gsl_vector_fprintf(stdout, x,
"%g");
161 gsl_permutation_free(p);
173 Matrix left{ { 0.18, 0.60, 0.57, 0.96 },
174 { 0.41, 0.24, 0.99, 0.58 },
175 { 0.14, 0.30, 0.97, 0.66 },
176 { 0.51, 0.13, 0.19, 0.85 } };
179 Vector right{ -4.05205, -12.6056, 1.66091, 8.69377 };
182 LU lusolver{ left, right };
184 const char *sep =
"---------------------";
185 ofs << sep << std::endl << left;
186 ofs << sep << std::endl << right;
187 ofs << sep << std::endl << lusolver.solution();
188 ofs << sep << std::endl << lusolver.get_left();
189 auto mupper = lusolver.upper_matrix();
190 ofs << sep << std::endl << mupper;
191 auto mlower = lusolver.lower_matrix();
192 ofs << sep << std::endl << mlower;
193 auto pmatrix = lusolver.permutation_matrix();
194 ofs << sep << std::endl << pmatrix;
195 ofs << sep << std::endl;
196 ofs << lusolver.permutation_vector();
197 ofs << sep << std::endl;
198 ofs << dot(pmatrix, left) << std::endl;
199 ofs << sep << std::endl;
200 ofs << dot(lusolver.lower_matrix(), lusolver.upper_matrix()) << std::endl;
void lu1()
lu1 Lösung eines linearen Gleichungssystems durch LU-Zerlegung
void lu3()
lu3 Lösung eines Gleichungssystems mittels der inversen Matrix
void lu0()
lu0 LU-Zerlegung einer Matrix Originalbeispiel mit Kommentaren. Lösung eines linearen Gleichungssyste...
The Matrix class Schnittstelle zur gsl Bibliothek.
void lu11()
lu11 Lösung eines linearen Gleichungssystems durch LU-Zerlegung
void solve()
solve Berechnung des Lösungsvektors
static std::ofstream get_stream(const std::string &fname)
get_output_stream Öffnen einer Ausgabedatei falls die Datei nicht geöffnet werden kann wird ein Fehle...
void lu2()
lu2 Lösung eines Gleichungssystems mit der Cramer'schen Regel
The LU_Decomposition class Lösung eines linearen Gleichungssystems mittels der LU-Zerlegung.
The Vector class Klasse für gsl-Vektoren zussamengesetzt aus Komponenten.
auto get_output_stream(const char *name, Format fmt=Output::csv)
get_output_stream generiere Ausgabestrom
static Matrix inverse(const Matrix &m)
inverse Berechnung der Inversen einer Matrix
static double det(const Matrix &m)
det Berechnung der Determinante