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

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" /* ------------------------------------ */ #define RA R5 #define CA C5 /* ------------------------------------ */ int main(void) { double xy[6] ={ 1, -2, 2, -3, 3, 6 }; double tA[RA*CA]={ /* x**2 y**2 x y e */ +1.00, +0.00, +0.00, +0.00, +0.00, +0.00, +1.00, +0.00, +0.00, +0.00, +1.00, +4.00, +1.00, -2.00, +1.00, +4.00, +9.00, +2.00, -3.00, +1.00, +9.00, +36.00, +3.00, +6.00, +1.00 }; double tb[RA*C1]={ /* = 0 */ +1.00, +1.00, +0.00, +0.00, +0.00 }; double **XY = ca_A_mR(xy,i_mR(R3,C2)); double **A = ca_A_mR(tA,i_mR(RA,CA)); double **b = ca_A_mR(tb,i_mR(RA,C1)); double **Inv = i_mR(CA,RA); double **Invb = i_mR(CA,C1); clrscrn(); printf("\n"); printf(" Find the coefficients a, b, c, d, of a circle \n\n"); printf(" ax**2 + ay**2 + bx + cy + d = 0 \n\n"); printf(" that passes through these three XY. \n\n"); printf(" x y"); p_mR(XY,S5,P0,C6); stop(); clrscrn(); printf(" Using the given XY, we obtain this matrix.\n"); printf(" (a = 1. This is my choice)\n\n"); printf(" A :"); p_mR(A,S10,P2,C7); printf(" b :"); p_mR(b,S10,P2,C7); printf(" Inv :"); invgj_mR(A,Inv); pE_mR(Inv,S12,P4,C10); stop(); clrscrn(); printf(" Inv :"); p_mR(Inv,S10,P4,C10); printf(" x = Inv * b "); mul_mR(Inv,b,Invb); p_mR(Invb,S10,P4,C10); printf(" The coefficients a, b, c, d, e, of the curve are : \n\n" " %+.2fx**2 %+.2fy**2 %+.2fx %+.2fy %+.2f = 0\n\n" ,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1], Invb[R4][C1],Invb[R5][C1]); stop(); f_mR(XY); f_mR(A); f_mR(b); f_mR(Inv); f_mR(Invb); return 0; } /* ------------------------------------ */ /* ------------------------------------ */ Screen output example: Find the coefficients a, b, c, d, of a circle ax**2 + ay**2 + bx + cy + d = 0 that passes through these three XY. x y +1 -2 +2 -3 +3 +6 Press return to continue. Using the given XY, we obtain this matrix. (a = 1. This is my choice) A : +1.00 +0.00 +0.00 +0.00 +0.00 +0.00 +1.00 +0.00 +0.00 +0.00 +1.00 +4.00 +1.00 -2.00 +1.00 +4.00 +9.00 +2.00 -3.00 +1.00 +9.00 +36.00 +3.00 +6.00 +1.00 b : +1.00 +1.00 +0.00 +0.00 +0.00 Inv : +1.0000e+00 +0.0000e+00 +2.2204e-16 +0.0000e+00 +0.0000e+00 +1.3878e-17 +1.0000e+00 +1.3878e-17 +0.0000e+00 +3.4694e-18 -3.2000e+00 -7.2000e+00 -9.0000e-01 +8.0000e-01 +1.0000e-01 -2.0000e-01 -2.2000e+00 +1.0000e-01 -2.0000e-01 +1.0000e-01 +1.8000e+00 -1.2000e+00 +2.1000e+00 -1.2000e+00 +1.0000e-01 Press return to continue. Inv : +1.0000 +0.0000 +0.0000 +0.0000 +0.0000 +0.0000 +1.0000 +0.0000 +0.0000 +0.0000 -3.2000 -7.2000 -0.9000 +0.8000 +0.1000 -0.2000 -2.2000 +0.1000 -0.2000 +0.1000 +1.8000 -1.2000 +2.1000 -1.2000 +0.1000 x = Inv * b +1.0000 +1.0000 -10.4000 -2.4000 +0.6000 The coefficients a, b, c, d, e, of the curve are : +1.00x**2 +1.00y**2 -10.40x -2.40y +0.60 = 0 Press return to continue. Copy and paste in Octave: function xy = f (x,y) xy = +1.00*x^2 +1.00*y^2 -10.40*x -2.40*y +0.60; endfunction f (+1,-2) f (+2,-3) f (+3,+6)