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

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 RA R5 #define CA C5 /* ------------------------------------ */ #define FACTOR_E +1.E-2 /* ------------------------------------ */ int main(void) { double txy[6] ={ 1, -1, 2, -9, 3, -8 }; double tA[RA*CA]={ /* x**2 y**2 x y e */ +1, +0, +0, +0, +0, +0, +1, +0, +0, +0, +1, +1, +1, -1, +1, +4, +81, +2, -9, +1, +9, +64, +3, -8, +1, }; double tb[RA*C1]={ /* = 0 */ +1, +1, +0, +0, +0, }; double **xy = ca_A_mR(txy, 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 **Pinv = Pinv_Rn_mR(A, i_mR(CA,RA),FACTOR_E); double **Pinvb = mul_mR(Pinv,b, 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(" Pinv = V invS_T U_T "); pE_mR(Pinv, S12,P4,C10); stop(); clrscrn(); printf(" Pinv = V invS_T U_T "); p_mR(Pinv, S10,P4,C10); printf(" Pinv b "); p_mR(Pinvb, S10,P4,C10); printf(" The coefficients a, b, c, d, e, of the curve are: \n\n" " %+.9f*x^2 %+.9f*y^2 %+.9f*x %+.9f*y %+.9f = 0\n\n" ,Pinvb[R1][C1],Pinvb[R2][C1],Pinvb[R3][C1], Pinvb[R4][C1],Pinvb[R5][C1]); stop(); f_mR(xy); f_mR(A); f_mR(b); f_mR(Pinv); f_mR(Pinvb); 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 -1 +2 -9 +3 -8 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 +1.00 +1.00 -1.00 +1.00 +4.00 +81.00 +2.00 -9.00 +1.00 +9.00 +64.00 +3.00 -8.00 +1.00 b : +1.00 +1.00 +0.00 +0.00 +0.00 Pinv = V * invS_T * U_T +1.0000e+00 +9.7165e-09 -4.4193e-09 -3.6790e-09 +4.5744e-09 +1.8872e-07 +1.0000e+00 +3.1730e-08 +2.7938e-08 -3.6322e-08 -4.7778e+00 +6.2222e+00 -1.1111e-01 -7.7778e-01 +8.8889e-01 -2.2222e-01 +1.0778e+01 +1.1111e-01 -2.2222e-01 +1.1111e-01 +3.5556e+00 +3.5556e+00 +1.2222e+00 +5.5556e-01 -7.7778e-01 Press return to continue. Pinv = V * invS_T * U_T +1.0000 +0.0000 -0.0000 -0.0000 +0.0000 +0.0000 +1.0000 +0.0000 +0.0000 -0.0000 -4.7778 +6.2222 -0.1111 -0.7778 +0.8889 -0.2222 +10.7778 +0.1111 -0.2222 +0.1111 +3.5556 +3.5556 +1.2222 +0.5556 -0.7778 Pinv * b +1.0000 +1.0000 +1.4444 +10.5556 +7.1111 The coefficients a, b, c, d, e, of the curve are : +0.999999988*x^2 +1.000000219*y^2 +1.444445879*x +10.555557922*y +7.111111809 = 0 Press return to continue. Copy and paste in Octave: function xy = f (x,y) xy = +0.999999988*x^2 +1.000000219*y^2 +1.444445879*x +10.555557922*y +7.111111809; endfunction f (+1,-1) f (+2,-9) f (+3,-8)