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

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 R2 #define CA C3 #define Cb C1 #define Rv C3 /* ------------------------------------ */ # define FREEV C1 /* ------------------------------------ */ int main(void) { double ab[RAb*(CA+Cb)]={ +4, +3, -1, -0, /* V1|0 See c00a.c */ -1, -1, +2, -0 /* V2|0 */ }; double Projp[Rv*C1] ={ -6.454545454546, -6.272727272728, +11.636363636364 }; 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 **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(" vQ is orthogonal to the vectors v1 and v2.\n\n" " The equation of a plan defined by v1 and v2\n" " is ax + by + cz=0, where a,b,c 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 plan (See c00d.c)\n\n" " vPp:"); p_mR(vPp, S10,P12,C1); printf(" vQ is orthogonal to the plan defined by the vectors v1 and v2.\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 plan v1 and v2.\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 plane. 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 plane. Screen output example: Compute the orthogonal vectors to: (See c00a .c) v1: +4.0000 +3.0000 -1.0000 v2: -1.0000 -1.0000 +2.0000 vQ is orthogonal to the vectors v1 and v2. The equation of a plan defined by v1 and v2 is ax + by + cz=0, where a,b,c are the coordinates of the vector orthogonal (vQ). vQ: -5.000000000000 +7.000000000000 +1.000000000000 Press return to continue. vPp is the projection of a point P onto the plan (See c00d.c) vPp: -6.454545454546 -6.272727272728 +11.636363636364 vQ is orthogonal to the plan defined by the vectors v1 and v2. vQ: -5.000000000000 +7.000000000000 +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 plan v1 and v2. Press return to continue.