void simply_LU_fatoration(Matrix *A, Matrix *x, Matrix *b){ /*Resolvemos * Ax = B * * fazendo A = LU * Ax = LUx = b * definimos Ux = c * e portanto * basta resolver * - Lc = b * - Ux = c * * aplica-se substituição direta no primeiro * e inversa no segundo * **PARA CASO ACHE 0 NA DIAGONAL PRINCIPAL** * */ Matrix *L, *U, *c; if(A && x && b) { if(A->columns != A->rows) { printf("solve_by_LU_fatoration recebeu A não quadrado!\n"); } else { get_simply_LU_fatoration(A, &L, &U); c = new_M(x->rows, x->columns); if(check_diagonal(U)) { printf("A matriz A é:\n"); print_M(A); printf("A matriz b é:\n"); print_M(b); printf("A fatoração L é:\n"); print_M(L); printf("A fatoração U é:\n"); print_M(U); ForwardSubstitution(L, c, b); BackSubstitution(U, x, c); printf("A solução x é:\n"); print_M(x); }//end if check else { printf("Falha na fatoração LU! U apresenta 0's na diagonal!\n"); } kill_M(&L); kill_M(&U); kill_M(&c); }//end else A quadrado }//end if existe else printf("solve_by_LU_fatoration recebeu alguma matriz que n existe!\n"); }
// decode bool NC::Decode(std::vector<CodedBlockPtr> *buffer, unsigned char ***m_data, int num_gens) { int i, j, num_blocks_gen, block_size; // NOTE: create m_upper here unsigned char ***m_upper; m_upper = new unsigned char **[num_gens]; for (i = 0; i < num_gens; ++i) { // WARNING: we require there's at least one code block in each buffer! // NOTE: we obtain num_blocks_gen for each generation in case it's variable num_blocks_gen = buffer[i][0]->num_blocks_gen; block_size = buffer[i][0]->block_size; m_upper[i] = new unsigned char*[num_blocks_gen]; for (j = 0; j < num_blocks_gen; ++j) { m_upper[i][j] = new unsigned char[num_blocks_gen + (is_sim ? 1 : block_size)]; memset(m_upper[i][j], 0, num_blocks_gen + (is_sim ? 1 : block_size)); } } // actual decoding's done here for (i = 0; i < num_gens; i++) { num_blocks_gen = buffer[i][0]->num_blocks_gen; block_size = buffer[i][0]->block_size; for (j = 0; j < num_blocks_gen; j++) { IncrementalDecode(m_upper, buffer[i][j]); } BackSubstitution(buffer, m_upper, m_data, i); } // NOTE: delete m_upper for (i = 0; i < num_gens; ++i) { num_blocks_gen = buffer[i][0]->num_blocks_gen; block_size = buffer[i][0]->block_size; for (j = 0; j < num_blocks_gen; ++j) { delete[] (m_upper[i][j]); } } return true; }
void Permuted_LU_fatoration(Matrix *A, Matrix *x, Matrix *b){ /*Resolvemos * Ax = B * * fazendo PA = LU * PAx = LUx = Pb = B * definimos Ux = c * e portanto * basta resolver * - Lc = B * - Ux = c * * aplica-se substituição direta no primeiro * e inversa no segundo * **TENTA CORRIGIR CASO ACHE 0 NA DIAGONAL PRINCIPAL** * */ Matrix *L, *U,*P, *B, *c; //L:matriz trang inferior especial //U:matriz triang superior com diagonal não nula //P:matriz das permutações //B: permutação aplicada em b //c: para o sistema auxlia Lc = B if(A && x && b) { if(A->columns != A->rows) { printf("solve_by_LU_fatoration recebeu A não quadrado!\n"); } else { get_Permuted_LU_fatoration(A, &L, &U, &P); B = M_cross_N(P, b); c = new_M(x->rows, x->columns); if(check_diagonal(U)) { printf("A matriz A é:\n"); print_M(A); printf("A matriz b é:\n"); print_M(b); printf("A matriz P é:\n"); print_M(P); printf("A matriz B é:\n"); print_M(B); printf("A fatoração L é:\n"); print_M(L); printf("A fatoração U é:\n"); print_M(U); ForwardSubstitution(L, c, B); printf(" c é:\n"); print_M(c); BackSubstitution(U, x, c); printf("A solução x é:\n"); print_M(x); }//end if check else { printf("Falha na fatoração LU! U apresenta 0's na diagonal!\n"); } kill_M(&L); kill_M(&U); kill_M(&c); kill_M(&P); kill_M(&B); }//end else A quadrado }//end if existe else printf("solve_by_LU_fatoration recebeu alguma matriz que n existe!\n"); }