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/a0dx

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 : c00b.c */ /* ------------------------------------ */ #include "v_a.h" /* ------------------------------------ */ /* ------------------------------------ */ void fun(int r,int c) { double **A = r_mR( i_mR(r,c),9.); double **U = svd_U_Cn_mR(A, i_mR(r,r)); double **US = i_mR(r,c); /* rr rc */ double **U_T = transpose_mR(U, i_mR(r,r)); double **U_TA = i_mR(r,c); /* rr rc */ double **V = svd_V_Cn_mR(A, i_mR(c,c)); double **V_T = transpose_mR(V, i_mR(c,c)); double **S = i_mR(r,c); clrscrn(); printf(" Copy/Paste into the octave windows \n\n\n"); p_Octave_mR(A,"A",P2); printf(" [U, S, V] =svd (A,10)\n\n\n"); stop(); clrscrn(); printf(" U :"); p_mR(U ,S10,P6,C10); printf(" V "); p_mR(V,S10,P6,C10); /* S = U_T A V */ mul_mR(U_T,A,U_TA); mul_mR(U_TA,V,S); printf(" S = U_T A V :"); p_mR(S,S10,P5,C10); stop(); clrscrn(); printf(" A :"); p_mR(A ,S10,P6,C10); /* A = U S V_T */ mul_mR(U,S,US); mul_mR(US,V_T,A); printf(" A = U S V_T "); p_mR(A,S10,P6,C10); f_mR(A); f_mR(U); f_mR(US); f_mR(U_T); f_mR(U_TA); f_mR(V); f_mR(V_T); f_mR(S); } /* ------------------------------------ */ int main(void) { time_t t; srand(time(&t)); int i; do { i = rp_I(R3)+R1; fun(i,i+C3); } while(stop_w()); return 0; } /* ------------------------------------ */ /* ------------------------------------ */ Screen output example: Copy/Paste into the octave windows A=[ -2.00,+6.00,+6.00,-6.00,+9.00,-1.00; +9.00,-2.00,+9.00,+5.00,+2.00,+7.00; -4.00,+2.00,-1.00,+1.00,+6.00,-8.00] [U, S, V] =svd (A,10) Press return to continue. U : -0.306795 +0.859760 -0.408276 +0.798535 +0.465930 +0.381118 -0.517898 +0.209098 +0.829494 V +0.570767 +0.112004 +0.135292 +0.699861 -0.000000 +0.000000 -0.258651 +0.317716 -0.226241 +0.000000 +0.000000 +0.862317 +0.339035 +0.625380 +0.021986 +0.000000 +0.616538 -0.000000 +0.307328 -0.179198 +0.755358 -0.423873 -0.150193 +0.406206 -0.246963 +0.678832 +0.300806 -0.187446 -0.569240 -0.299432 +0.580465 +0.049862 -0.518630 -0.543499 -0.522771 +0.041781 S = U_T A V : +17.29602 +0.00000 +0.00000 +0.00000 -0.00000 -0.00000 +0.00000 +14.61964 -0.00000 +0.00000 +0.00000 -0.00000 +0.00000 +0.00000 +6.86395 +0.00000 -0.00000 +0.00000 Press return to continue. A : -2.000000 +6.000000 +6.000000 -6.000000 +9.000000 -1.000000 +9.000000 -2.000000 +9.000000 +5.000000 +2.000000 +7.000000 -4.000000 +2.000000 -1.000000 +1.000000 +6.000000 -8.000000 A = U S V_T -2.000000 +6.000000 +6.000000 -6.000000 +9.000000 -1.000000 +9.000000 -2.000000 +9.000000 +5.000000 +2.000000 +7.000000 -4.000000 +2.000000 -1.000000 +1.000000 +6.000000 -8.000000 Press return to continue Press X return to stop