Chuong02 a=LU

Embed Size (px)

Citation preview

  • 7/27/2019 Chuong02 a=LU

    1/4

    /** DIRECT FACTORIZATION ALGORITHM 6.4** To factor the n by n matrix A = (A(I,J)) into the product of the* lower triangular matrix L = (L(I,J)) and U = (U(I,J)), that is* A = LU, where the main diagonal of either L or U consists of all ones:** INPUT: dimension n; the entries A(I,J), 1

  • 7/27/2019 Chuong02 a=LU

    2/4

    /* STEP 3 */M = N - 1;I = 2;while ((I

  • 7/27/2019 Chuong02 a=LU

    3/4

    printf("This is the general LU factorization method.\n");printf("The array will be input from a text file in the order:\n");printf("A(1,1), A(1,2), ..., A(1,N), A(2,1), A(2,2), ..., A(2,N),\n");printf("..., A(N,1), A(N,2), ..., A(N,N)\n\n");printf("Place as many entries as desired on each line, but separate ");printf("entries with\n");printf("at least one blank.\n\n\n");printf("Has the input file been created? - enter Y or N.\n");scanf("%c",&AA);*OK = false;if ((AA == 'Y') || (AA == 'y')) {

    printf("Input the file name in the form - drive:name.ext\n");printf("for example: A:DATA.DTA\n");scanf("%s", NAME);INP = fopen(NAME, "r");*OK = false;while (!(*OK)) {

    printf("Input the dimension n - an integer.\n");scanf("%d", N);if (*N > 0) {

    for (I=1; I

  • 7/27/2019 Chuong02 a=LU

    4/4

    if (ISW == 0)fprintf(OUP, "The diagonal of L consists of all entries = 1.0\n");

    elsefprintf(OUP, "The diagonal of U consists of all entries = 1.0\n");

    fprintf(OUP, "\nEntries of L below/on diagonal and entries of U above");fprintf(OUP, "/on diagonal\n");fprintf(OUP, "- output by rows in overwrite format:\n");for (I=1; I