static void calc_rhs_Tr_m(int n_models, MAT **Vk,MAT *VinvIminAw, VEC *y, VEC *rhs, MAT *Tr_m) { int j, k; MAT **Pr = NULL, *Tmp = MNULL; VEC *v_tmp = VNULL, *v_tmp2; Pr = (MAT **) emalloc(n_models * sizeof(MAT *)); v_tmp2 = vm_mlt(VinvIminAw, y, VNULL); /* Vw-(I-Aw)Y == Y'(I-Aw)'Vw- */ for (j = 0; j < n_models; j++) { Pr[j] = m_mlt(Vk[j], VinvIminAw, MNULL); Tmp = m_mlt(Pr[j], Pr[j], Tmp); Tr_m->me[j][j] = trace_matrix(Tmp); /* diagonal */ /* using Tr(A B) == Tr(B A) */ for (k = 0; k < j; k++) { /* we did Pr[k] and Pr[j], so */ Tmp = m_mlt(Pr[j], Pr[k], Tmp); /* off-diagonal */ Tr_m->me[j][k] = Tr_m->me[k][j] = trace_matrix(Tmp); } v_tmp = vm_mlt(Vk[j], v_tmp2, v_tmp); /* Vw-1(I-Aw)Y */ rhs->ve[j] = in_prod(v_tmp2, v_tmp); } for (j = 0; j < n_models; j++) m_free(Pr[j]); efree(Pr); m_free(Tmp); v_free(v_tmp); v_free(v_tmp2); return; }
pivot (matrix A1, matrix B) { int n, i, j, k; real p, q; n = DIM (A1, 0); MATRIX (A, MAX*MAX, n, n); copy_matrix (A1, A); for (i=0; i<n; i++) for (j=0; j<n; j++) { VAL2 (B, i, j) = i == j; } trace_matrix ("B initiale", B); for (i=0; i<n; i++) { p = VAL2 (A, i, i); /* ajouter traitement cas p = 0 */ /* on divise la 1ere ligne par le pivot */ for (j=0; j<n; j++) { VAL2 (A, i, j) /= p; VAL2 (B, i, j) /= p; } trace_matrix ("A", A); trace_matrix ("B", B); for (k=0; k<n; k++) if (k != i) { q = VAL2 (A, k, i); for (j=0; j<n; j++) { VAL2 (A, k, j) -= q * VAL2 (A, i, j); VAL2 (B, k, j) -= q * VAL2 (B, i, j); } } trace_matrix ("A", A); trace_matrix ("B", B); } ENDMAT }
/* Print a matrix */ static void trace_matrix_fixed(const gs_matrix_fixed * pmat) { trace_matrix((const gs_matrix *)pmat); if (pmat->txy_fixed_valid) { dprintf2("\t\tt_fixed: [%6g %6g]\n", fixed2float(pmat->tx_fixed), fixed2float(pmat->ty_fixed)); } else { dputs("\t\tt_fixed not valid\n"); } }
int gs_concat(gs_state * pgs, const gs_matrix * pmat) { gs_matrix cmat; int code = gs_matrix_multiply(pmat, &ctm_only(pgs), &cmat); if (code < 0) return code; update_ctm(pgs, cmat.tx, cmat.ty); set_ctm_only(pgs, cmat); #ifdef DEBUG if (gs_debug_c('x')) dlprintf("[x]concat:\n"), trace_matrix(pmat), trace_ctm(pgs); #endif return code; }