diff --git a/Projekt1_Knuettel_Daniel.c b/Projekt1_Knuettel_Daniel.c index 750c1cf..10c94ab 100644 --- a/Projekt1_Knuettel_Daniel.c +++ b/Projekt1_Knuettel_Daniel.c @@ -161,6 +161,8 @@ int main(void) A_1[i][j] = A_stack_1[n*i + j]; } } + printf("A:\n"); + printm(A_1, m, n); double * alpha_1 = malloc(sizeof(double) * m); @@ -192,7 +194,10 @@ int main(void) goto exit; } + printf("R:\n"); printm(R_1, m, n); + + printf("Generating vectors of Q:\n"); for(i = 0; i < n; i++) { printv(vs_1[i], m); @@ -206,6 +211,68 @@ int main(void) } free(R_1); + free(alpha_1); + for(i = 0; i < m; i++) + { + free(A_1[i]); + } + free(A_1); + + + + double A_stack_2[16] = {2, -1, 3, 0 + , 7, 0, 1.4142135623730951, 1 + , 1, 1, 1, 1 + , 0, 10, 3, 2 + }; + + m = 4; + n = 4; + + double ** A_2 = malloc(sizeof(double *) * m); + for(i = 0; i < m; i++) + { + A_2[i] = malloc(sizeof(double) * n); + for(j = 0; j < n; j++) + { + A_2[i][j] = A_stack_2[n*i + j]; + } + } + + double * b = malloc(sizeof(double) * m); + double b_stack[4] = {1, 0, 0, 0}; + + for(i = 0; i < m; i++) + { + b[i] = b_stack[i]; + } + + printf("System: A, b\n"); + printm(A_2, m, m); + printv(b, m); + + + double * alpha_2 = malloc(sizeof(double) * m); + + status = householder(A_2, alpha_2, m, n); + if(status) + { + fprintf(stderr, "failed to compute QR decomposition\n"); + goto exit; + } + + status = solve_QR(A_2, alpha_2, m, b); + printf("Solution for the System:\n"); + printv(b, m); + + free(alpha_2); + for(i = 0; i < m; i++) + { + free(A_2[i]); + } + free(A_2); + free(b); +