Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Linear Algebra and the C Language/a0ne

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

__NOTOC__ Install and compile this file in your working directory. /* ------------------------------------ */ /* Save as : c00a.c */ /* ------------------------------------ */ #include "v_a.h" /* ------------------------------------ */ /* ------------------------------------ */ void fun(int r,int c) { double **A = r_mR( i_mR(r,c),9.); double **A_T = transpose_mR(A, i_mR(c,r)); double **Svalues = svds_mR(A_T, i_mR(r,C1)); double s = 0; int i = 0; clrscrn(); printf(" A:"); p_mR(A, S5,P0,C10); printf(" Singular values:"); p_mR(Svalues, S5,P5,C10); stop(); clrscrn(); for(i=R1;i<=r;i++) s += Svalues[i][C1]; printf(" Sum of the singular values of A : s = %.3f\n\n\n", s); printf(" The contribution of each singular value in percentage\n\n"); for(i=R1;i<=r;i++) printf(" 100 Svalues[%d]/s = %+.3f%%\n",i,(100*Svalues[i][C1])/s); printf("\n\n\n" " The contribution of each singular value in proportion\n\n"); for(i=R1;i<=r;i++) printf(" Svalues[%d]/s = %+.3f\n",i,(Svalues[i][C1])/s); f_mR(A); f_mR(A_T); f_mR(Svalues); } /* ------------------------------------ */ int main(void) { time_t t; srand(time(&t)); do { fun(R4,C6); } while(stop_w()); return 0; } /* ------------------------------------ */ /* ------------------------------------ */ In this example, we will study the contribution of each singular value in the matrix. If the matrix represents an image, we could remove all singular values ​​with a small contribution and their corresponding singular vectors to compress the image without degrading it. Screen output example: A: +7 +6 +9 -4 -2 +6 +1 +4 +4 +1 +7 +7 +7 +6 +1 -8 -6 +4 +5 -5 +7 +7 -9 +5 Singular values: +20.82396 +15.06937 +11.75594 +3.32782 Press return to continue. Sum of the singular values of A : s = 50.977 The contribution of each singular value in percentage 100 Svalues[1]/s = +40.850% 100 Svalues[2]/s = +29.561% 100 Svalues[3]/s = +23.061% 100 Svalues[4]/s = +6.528% The contribution of each singular value in proportion Svalues[1]/s = +0.408 Svalues[2]/s = +0.296 Svalues[3]/s = +0.231 Svalues[4]/s = +0.065 Press return to continue Press X return to stop