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

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. thumb| /* ------------------------------------ */ /* Save as : c00a.c */ /* ------------------------------------ */ #include "v_a.h" /* ------------------------------------ */ /* ------------------------------------ */ #define RA R4 #define CA C3 #define Cb C1 /* ------------------------------------ */ /* ------------------------------------ */ int main(void) { double ta[RA*(CA+Cb)]={ // I1 I2 I3 +1, +1, -1, -60, +30, +0, +0, +30, +20, +60, +0, +20, }; double tb[RA*(CA+Cb)]={ // I1 I2 I3 +0, +0, +120, +120 }; double **A = ca_A_mR(ta,i_mR(RA,CA)); double **b = ca_A_mR(tb,i_mR(RA,Cb)); double **Q = i_mR(RA,CA); double **Q_T = i_mR(CA,RA); double **R = i_mR(CA,CA); double **invR = i_mR(CA,CA); double **invR_Q_T = i_mR(CA,RA); double **x = i_mR(CA,C1); clrscrn(); printf(" Copy/Paste into the octave windows \n\n"); p_Octave_mR(A,"a",P0); printf(" [Q, R] = qr (a,0) \n\n"); QR_mR(A,Q,R); printf(" Q :"); p_mR(Q, S10,P4, C10); printf(" R :"); p_mR(R, S10,P4, C10); stop(); clrscrn(); transpose_mR(Q,Q_T); printf(" Q_T :"); pE_mR(Q_T,S9,P5, C3); invgj_mR(R,invR); printf(" invR :"); pE_mR(invR,S9,P5, C6); stop(); clrscrn(); printf(" Solving this system yields a unique\n" " least squares solution, namely \n\n"); mul_mR(invR,Q_T,invR_Q_T); mul_mR(invR_Q_T,b,x); printf(" x = invR * Q_T * b :"); p_mR(x,S9,P5 ,C6); stop(); f_mR(A); f_mR(b); f_mR(Q); f_mR(Q_T); f_mR(R); f_mR(invR); f_mR(x); return 0; } /* ------------------------------------ */ /* ------------------------------------ */ thumb| Screen output example: Copy/Paste into the octave windows a=[ +1,+1,-1; -60,+30,+0; +0,+30,+20; +60,+0,+20] [Q, R] = qr (a,0) Q : +0.0118 +0.0340 -0.9994 -0.7071 +0.4083 +0.0056 +0.0000 +0.8160 +0.0278 +0.7071 +0.4077 +0.0222 R : +84.8587 -21.1999 +14.1294 +0.0000 +36.7636 +24.4411 -0.0000 +0.0000 +1.9987 Press return to continue. Q_T : +1.17843e-02 -7.07058e-01 +0.00000e+00 +3.39963e-02 +4.08296e-01 +8.16025e-01 -9.99352e-01 +5.55196e-03 +2.77598e-02 +7.07058e-01 +4.07729e-01 +2.22078e-02 invR : +1.17843e-02 +6.79548e-03 -1.66405e-01 +0.00000e+00 +2.72008e-02 -3.32624e-01 -0.00000e+00 -0.00000e+00 +5.00324e-01 Press return to continue. Solving this system yields a unique least squares solution, namely x = invR * Q_T * b : +1.00000 +2.00000 +3.00000 Press return to continue.