Added some more useful stuff

This commit is contained in:
Daniel Knüttel 2018-11-12 19:42:40 +01:00
parent 75ee16b6a0
commit c607424231

View File

@ -31,6 +31,14 @@
* Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
*/
/*
* General Information:
*
* - Matrices are represented using line vectors. This is
* convenient for accessing elements.
*
* */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
@ -262,6 +270,31 @@ int main(void)
}
status = solve_QR(A_2, alpha_2, m, b);
double ** R_2;
status = unwind_R(A_2, alpha_2, m, n, &R_2);
if(status)
{
fprintf(stderr, "failed to unwind R\n");
free(alpha_2);
for(i = 0; i < m; i++)
{
free(A_2[i]);
}
free(A_2);
free(b);
goto exit;
}
printf("R:\n");
printm(R_2, m, n);
for(i = 0; i < m; i++)
{
free(R_2[i]);
}
free(R_2);
printf("Solution for the System:\n");
printv(b, m);
@ -358,6 +391,9 @@ int fprintm(FILE * stream, double ** matrix, int m, int n)
for(j = 0; j < n; j++)
{
#ifdef DEBUG
fprintf(stderr, "matrix[%d][%d] = %f\n", i, j, matrix[i][j]);
#endif
fprintf(stream, "%6.2f ", matrix[i][j]);
}
@ -526,6 +562,9 @@ int unwind_R(double ** A, double * alpha, int m, int n, double *** R)
{
for(j = 0; j < n; j++)
{
#ifdef DEBUG
fprintf(stderr, "set result[%d][%d]\n", i, j);
#endif
if(i > j)
{
result[i][j] = 0;