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

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" /* ------------------------------------ */ #define RC R3 #define Cb C3 /* ------------------------------------ */ int main(void) { double ta[RC*RC] ={ 4,2,3, 5,3,1, 8,2,2}; double tb[RC*Cb] ={ 3, 4, 9, 2, 5, 8, 1, 6, 7}; double **A = ca_A_mR(ta, i_mR(RC,RC)); double **B = ca_A_mR(tb, i_mR(RC,Cb)); double **InvA = inv_mR(A, i_mR(RC,RC)); double **X = mul_mR(InvA,B, i_mR(RC,Cb)); clrscrn(); printf(" \n"); printf(" Linear systems with common coefficient matrix.\n\n"); printf(" Ax1=b1 \n"); printf(" Ax2=b2 \n"); printf(" ... \n"); printf(" Axn=bn \n\n"); printf(" We can write these equalities in this maner. \n\n"); printf(" A|x1|x2|...|xn| = b1|b2|...|bn| \n\n"); printf(" or simply : \n\n"); printf(" AX = B \n\n"); printf(" where B = b1|b2|...|bn \n\n"); printf(" and X = x1|x2|...|xn \n\n"); stop(); clrscrn(); printf(" We want to find X such as, \n\n"); printf(" AX = B \n\n"); printf(" If A is a square matrix and, \n\n"); printf(" If A has an inverse matrix, \n\n"); printf(" you can find X by this method\n\n"); printf(" X = inv(A) B \n\n\n"); printf(" To verify the result you can \n\n"); printf(" multiply the matrix A by X. \n\n"); printf(" You must refind B. \n\n"); stop(); clrscrn(); printf(" A :"); p_mR(A, S5,P0,C6); printf(" b1 b2 ... bn :"); p_mR(B, S9,P0,C6); stop(); clrscrn(); printf(" inv(A):"); pE_mR(InvA, S1,P4,C6); printf(" X = inv(A) B :\n\n"); printf(" x1 x2 ... xn"); p_mR(X, S9,P4,C6); stop(); clrscrn(); printf(" b1 b2 ... bn :"); p_mR(B, S9,P0,C6); printf(" Ax1 Ax2 ... Axn :"); p_mR(mul_mR(A,X,B), S9,P0,C6); stop(); f_mR(X); f_mR(B); f_mR(InvA); f_mR(A); return 0; } /* ------------------------------------ */ /* ------------------------------------ */ Screen output example: Linear systems with common coefficient matrix. Ax1=b1 Ax2=b2 ... Axn=bn We can write these equalities in this maner. A|x1|x2|...|xn| = b1|b2|...|bn| or simply : AX = B where B = b1|b2|...|bn and X = x1|x2|...|xn Press return to continue. We want to find X such as, AX = B If A is a square matrix and, If A has an inverse matrix, you can find X by this method X = inv(A) B To verify the result you can multiply the matrix A by X. You must refind B. Press return to continue. A : +4 +2 +3 +5 +3 +1 +8 +2 +2 b1 b2 ... bn : +3 +4 +9 +2 +5 +8 +1 +6 +7 Press return to continue. inv(A) : -1.3333e-01 -6.6667e-02 +2.3333e-01 +6.6667e-02 +5.3333e-01 -3.6667e-01 +4.6667e-01 -2.6667e-01 -6.6667e-02 X = inv(A) * B : x1 x2 ... xn -0.3000 +0.5333 -0.1000 +0.9000 +0.7333 +2.3000 +0.8000 +0.1333 +1.6000 Press return to continue. b1 b2 ... bn : +3 +4 +9 +2 +5 +8 +1 +6 +7 Ax1 Ax2 ... Axn : +3 +4 +9 +2 +5 +8 +1 +6 +7 Press return to continue.