00001
00002
00003
00004
00005
00006
00007
00008 #include "nl.h"
00009
00010 int main()
00011 {
00012 double **A, *b, *t, *r;
00013 size_t m = 4;
00014 size_t n = 3;
00015
00016 A = nl_dmatrix_create(m, n);
00017 b = nl_dvector_create(m);
00018 t = nl_dvector_create(n);
00019 r = nl_dvector_create(m);
00020
00021 A[0][0] = 1; A[0][1] = 5; A[0][2] = 1; b[0] = 1;
00022 A[1][0] = 2; A[1][1] = 6; A[1][2] = 10; b[1] = 1;
00023 A[2][0] = 3; A[2][1] = 7; A[2][2] = 11; b[2] = 1;
00024 A[3][0] = 4; A[3][1] = 8; A[3][2] = 12; b[3] = 2;
00025
00026 printf("Матрица A:\n");
00027 nl_dmatrix_print(A, m, n, NULL);
00028
00029 qr_decomp(A, m, n, t);
00030
00031 printf("\nQR-разложение:\n");
00032 nl_dmatrix_print(A, m, n, NULL);
00033
00034 printf("\nВектор t:\n");
00035 nl_dvector_print(t, n, NULL);
00036
00037 printf("\nВектор b:\n");
00038 nl_dvector_print(b, m, NULL);
00039
00040 qr_least_squares (A, m, n, t, b, r);
00041
00042 printf("\nПсевдорешение системы Ax = b:\n");
00043 nl_dvector_print(b, n, NULL);
00044
00045 printf("\nНевязки:\n");
00046 nl_dvector_print(r, m, NULL);
00047
00048 nl_dmatrix_free(A, m);
00049 nl_dvector_free(b);
00050 nl_dvector_free(t);
00051 nl_dvector_free(r);
00052
00053 return 0;
00054 }