void pmat(double *mat, int n) /** print square matrix */ { int i,j ; double *diag ; ZALLOC(diag,n, double) ; getdiag(diag, mat, n) ; printf("pmat:\n") ; for (i=0; i<n; i++) { printf("diag %5d %9.3f\n",i, diag[i]) ; for (j=0; j<n; j++) { if ((j%10) == 9) printf("\n") ; if ((n%10) != 0) printf("%9.3f ",mat[i*n+j]) ; } printf("\n") ; } printf("\n") ; printf("\n") ; free(diag) ; }
double trace(double *a, int n) { double *diags, t ; ZALLOC(diags,n,double) ; getdiag(diags,a,n) ; /* extract diagonal */ t = asum(diags,n) ; free(diags) ; return t ; }