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

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 : c00e.c */ /* ------------------------------------ */ #include "v_a.h" /* ------------------------------------ */ #define RAb R3 #define CA C4 #define Cb C1 #define Rv C4 /* ------------------------------------ */ # define FREEV C1 /* ------------------------------------ */ int main(void) { double ab[RAb*(CA+Cb)]={ +4, +3, -1, -2, -0, /* V1|0 See c00a.c */ -1, -1, +2, -3, -0, /* V2|0 */ -2, -5, +4, -3, -0 /* V3|0 */ }; double Projp[Rv*C1] ={ -12.062500000000, -13.750000000000, +15.375000000000, -15.750000000000 }; double **Ab = ca_A_mR(ab, i_Abr_Ac_bc_mR(RAb, CA, Cb)); double **Ab_free = i_Abr_Ac_bc_mR(CA, CA, Cb + FREEV); double **b_free = i_mR(CA, Cb + FREEV); double **A = c_Ab_A_mR(Ab, i_mR(RAb, CA)); double **At = transpose_mR(A, i_mR(CA, RAb)); double **vPp = ca_A_mR(Projp, i_mR(Rv,C1)); double **v1 = i_mR(Rv,C1); double **v2 = i_mR(Rv,C1); double **v3 = i_mR(Rv,C1); double **vQ = i_mR(Rv,C1); /* Compute the free variables (b_free) */ gj_PP_mR(Ab,NO); put_zeroR_mR(Ab,Ab_free); put_freeV_mR(Ab_free); gj_PP_mR(Ab_free,YES); c_Ab_b_mR(Ab_free,b_free); clrscrn(); printf(" Compute the orthogonal vectors to: (See c00a .c)\n\n" " v1:"); p_mR(c_c_mR(At,(C1), v1,C1), S10,P4,C1); printf(" v2:"); p_mR(c_c_mR(At,(C2), v2,C1), S10,P4,C1); printf(" v3:"); p_mR(c_c_mR(At,(C3), v3,C1), S10,P4,C1); stop(); clrscrn(); printf(" vQ is orthogonal to the vectors v1,v2 and v3.\n\n" " The equation of a hyperplan defined by v1, v2 and v3\n" " is ax + by + cz + dt=0, where a,b,c,d are the coordinates\n" " of the vector orthogonal (vQ).\n\n" " vQ:"); p_mR(c_c_mR(b_free,C2, vQ,C1), S10,P12,C1); stop(); clrscrn(); printf(" vPp is the projection of a point P onto the hyperplan (See c00d.c)\n\n" " vPp:"); p_mR(vPp, S10,P12,C1); printf(" vQ is orthogonal to the hyperplan defined by the vectors v1,v2 and v3.\n\n" " vQ:"); p_mR(vQ, S10,P12,C1); printf(" dot(vPp,vQ) = %.9f\n\n" " The dot product of vQ and vPp say that the vector vPp \n" " is orthogonal to the vector vQ. Then the point p is in\n" " the hyperplan v1, v2 and v3.\n\n", dot_R(vPp,vQ)); stop(); f_mR(Ab); f_mR(Ab_free); f_mR(b_free); f_mR(v1); f_mR(v2); f_mR(vQ); return 0; } /* ------------------------------------ */ /* ------------------------------------ */ Check if the projection of a point P lies on the hyperplane. If the projection of point p, the vector vPp, is perpendicular to the vector vQ, then the dot product of these two vectors is zero and point Pp is indeed in the hyperplane. Screen output example: Compute the orthogonal vectors to: (See c00a .c) v1: +4.0000 +3.0000 -1.0000 -2.0000 v2: -1.0000 -1.0000 +2.0000 -3.0000 v3: -2.0000 -5.0000 +4.0000 -3.0000 Press return to continue. vQ is orthogonal to the vectors v1,v2 and v3. The equation of a hyperplan defined by v1, v2 and v3 is ax + by + cz + dt=0, where a,b,c,d are the coordinates of the vector orthogonal (vQ). vQ: +0.285714285714 +1.000000000000 +2.142857142857 +1.000000000000 Press return to continue. vPp is the projection of a point P onto the hyperplan (See c00d.c) vPp: -12.062500000000 -13.750000000000 +15.375000000000 -15.750000000000 vQ is orthogonal to the hyperplan defined by the vectors v1,v2 and v3. vQ: +0.285714285714 +1.000000000000 +2.142857142857 +1.000000000000 dot(vPp,vQ) = 0.000000000 The dot product of vQ and vPp say that the vector vPp is orthogonal to the vector vQ. Then the point p is in the hyperplan v1, v2 and v3. Press return to continue.