xband.c

00001 /*
00002   Пример использования функций из модуля @band.h@
00003   Решение ленточной системы
00004   $    \left\{    \begin{narrowarray}{rcrcrcrcrcrcrccr}       4 x\sb 1 & + &  x\sb 2 &   &         &   &         &   &         &   &         &   &         & ~=~ & 5, \\       2 x\sb 1 & + & 4x\sb 2 & + &  x\sb 3 &   &         &   &         &   &         &   &         & ~=~ & 7, \\         x\sb 1 & + & 2x\sb 2 & + & 4x\sb 3 & + &  x\sb 4 &   &         &   &         &   &         & ~=~ & 8, \\                &   &  x\sb 2 & + & 2x\sb 3 & + & 4x\sb 4 & + &  x\sb 5 &   &         &   &         & ~=~ & 8, \\                &   &         &   &  x\sb 3 & + & 2x\sb 4 & + & 4x\sb 5 & + &  x\sb 6 &   &         & ~=~ & 8, \\                &   &         &   &         &   &  x\sb 4 & + & 2x\sb 5 & + & 4x\sb 6 & + &  x\sb 7 & ~=~ & 8, \\                &   &         &   &         &   &         &   &  x\sb 5 & + & 2x\sb 6 & + & 4x\sb 7 & ~=~ & 7. \\    \end{narrowarray}      \right.   $.
00005 */
00006 
00007 #include "nl.h"
00008 
00009 int main()
00010 {
00011   size_t n = 7;
00012   size_t m1 = 2;
00013   size_t m2 = 1;
00014   size_t m = m1 + m2 + 1;
00015 
00016   size_t *p;
00017   double **C, **L, *b, *x;
00018   int sgn;
00019 
00020   C = nl_dmatrix_create(n, m);
00021   L = nl_dmatrix_create(n, m1);
00022   b = nl_dvector_create(n);
00023   x = nl_dvector_create(n);
00024   p = nl_xvector_create(n);
00025 
00026   C[0][0] = 0; C[0][1] = 0; C[0][2] = 4; C[0][3] = 1;
00027   C[1][0] = 0; C[1][1] = 2; C[1][2] = 4; C[1][3] = 1;
00028   C[2][0] = 1; C[2][1] = 2; C[2][2] = 4; C[2][3] = 1;
00029   C[3][0] = 1; C[3][1] = 2; C[3][2] = 4; C[3][3] = 1;
00030   C[4][0] = 1; C[4][1] = 2; C[4][2] = 4; C[4][3] = 1;
00031   C[5][0] = 1; C[5][1] = 2; C[5][2] = 4; C[5][3] = 1;
00032   C[6][0] = 1; C[6][1] = 2; C[6][2] = 4; C[6][3] = 0;
00033 
00034   x[0] = 1; x[1] = 1; x[2] = 1; x[3] = 1;
00035   x[4] = 1; x[5] = 1; x[6] = 1; 
00036  
00037   printf("\nМатрица A:\n");
00038   nl_dmatrix_print(C, n, m, NULL);
00039 
00040   band_mult_col(C, n, m1, m2, x, b);
00041    
00042   printf("\nВектор b:\n");
00043   nl_dvector_print(b, n, NULL);
00044 
00045   band_decomp(C, n, m1, m2, L, p, &sgn);
00046   band_solve(C, n, m1, m2, L, p, b);
00047 
00048   printf("\nРешение системы Ax = b:\n");
00049   nl_dvector_print(b, n, NULL);
00050 
00051   nl_dmatrix_free(C, n);
00052   nl_dmatrix_free(L, n);
00053   nl_dvector_free(b);
00054   nl_xvector_free(p);
00055   
00056   return 0;
00057 }

Документация по NL. Последние изменения: Mon Oct 9 12:25:54 2006. Создано системой  doxygen 1.4.7