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

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 : c05a.c */ /* ------------------------------------ */ #include "v_a.h" /* ------------------------------------ */ /* ------------------------------------ */ #define RA R5 #define CA C2 /* ------------------------------------ */ /* ------------------------------------ */ int main(void) { double a[RA*(CA)]={ 2, 0, 0, 3, 0, 0, 4, 5, 1, 0 }; double x[RA*(C1)]={ -1, 2, -3, -3, -1, }; double **A = ca_A_mR(a, i_mR(RA,CA)); double **AT = transpose_mR(A, i_mR(CA,RA)); double **ATA = mul_mR(AT,A, i_mR(CA,CA)); double **invATA = invgj_mR(ATA, i_mR(CA,CA)); double **invATA_AT = mul_mR(invATA,AT, i_mR(CA,RA)); double **V = mul_mR(A,invATA_AT,i_mR(RA,RA)); /* A inv(AT A) AT */ double **X = ca_A_mR(x, i_mR(RA,C1)); double **VX = mul_mR(V,X, i_mR(RA,C1)); clrscrn(); printf(" A is subspace of R%d \n\n" " Find a transformation matrix for \n" " a projection onto R%d. \n\n" " Proj(x) = A inv(AT A) AT \n\n",RA,RA); printf(" A:"); p_mR(A,S5,P1,C7); stop(); clrscrn(); printf(" AT:"); p_mR(AT,S5,P1,C7); printf(" AT A:"); p_mR(ATA,S5,P1,C7); printf(" inv(ATA):"); p_mR(invATA,S5,P4,C7); printf(" inv(ATA) AT:"); p_mR(invATA_AT,S5,P4,C7); printf(" V = A inv(ATA)AT"); p_mR(V,S5,P4,C7); stop(); clrscrn(); printf(" V is transformation matrix for \n" " a projection onto a R%d subspace \n\n" " V:",RA); p_mR(V,S5,P4,C7); printf(" X:"); p_mR(X,S5,P1,C7); stop(); clrscrn(); printf(" Proj(x) = A inv(ATA)AT x \n\n" " Proj(x) = V x Verify the result with the last C file"); p_mR(VX,S5,P4,C7); stop(); f_mR(A); f_mR(AT); f_mR(ATA); f_mR(invATA); f_mR(invATA_AT); f_mR(V); /* A inv(AT A) AT */ f_mR(X); f_mR(VX); return 0; } /* ------------------------------------ */ /* ------------------------------------ */ Screen output example: A is subspace of R5 Find a transformation matrix for a projection onto R5. Proj(x) = A inv(AT A) AT A: +2.0 +0.0 +0.0 +3.0 +0.0 +0.0 +4.0 +5.0 +1.0 +0.0 Press return to continue. AT: +2.0 +0.0 +0.0 +4.0 +1.0 +0.0 +3.0 +0.0 +5.0 +0.0 AT A: +21.0 +20.0 +20.0 +34.0 inv(ATA): +0.1083 -0.0637 -0.0637 +0.0669 inv(ATA) AT: +0.2166 -0.1911 +0.0000 +0.1146 +0.1083 -0.1274 +0.2006 +0.0000 +0.0796 -0.0637 V = A inv(ATA)AT +0.4331 -0.3822 +0.0000 +0.2293 +0.2166 -0.3822 +0.6019 +0.0000 +0.2389 -0.1911 +0.0000 +0.0000 +0.0000 +0.0000 +0.0000 +0.2293 +0.2389 +0.0000 +0.8567 +0.1146 +0.2166 -0.1911 +0.0000 +0.1146 +0.1083 Press return to continue. V is transformation matrix for a projection onto a R5 subspace V: +0.4331 -0.3822 +0.0000 +0.2293 +0.2166 -0.3822 +0.6019 +0.0000 +0.2389 -0.1911 +0.0000 +0.0000 +0.0000 +0.0000 +0.0000 +0.2293 +0.2389 +0.0000 +0.8567 +0.1146 +0.2166 -0.1911 +0.0000 +0.1146 +0.1083 X: -1.0 +2.0 -3.0 -3.0 -1.0 Press return to continue. Proj(x) = A inv(ATA)AT x Proj(x) = V x Verify the result with the last C file -2.1019 +1.0605 +0.0000 -2.4363 -1.0510 Press return to continue.