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

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: c00d2.c */ /* ------------------------------------ */ #include "v_a.h" /* ------------------------------------ */ /* ------------------------------------ */ #define RC RC3 /* ------------------------------------ */ /* ------------------------------------ */ int main(void) { double tu[RC*C1]={ -7, -6, +8 }; double tv[RC*C1]={ -5, -4, +7 }; double tQ[RC*RC]={ +0.4819, +0.4615, +0.7448, +0.6196, -0.7806, +0.0828, +0.6196, +0.4216, -0.6621 }; double **u = ca_A_mR(tu, i_mR(RC,C1)); double **v = ca_A_mR(tv, i_mR(RC,C1)); double **Q = ca_A_mR(tQ, i_mR(RC,RC)); double **Qu = mul_mR(Q,u, i_mR(RC,C1)); double **Qv = mul_mR(Q,v, i_mR(RC,C1)); clrscrn(); printf(" Calculate the cosine of the angle" " between vectors U and V: \n\n"); printf(" u:"); p_mR(u, S3,P0,C6); printf(" v:"); p_mR(v, S3,P0,C6); printf(" <u,v> \n" " cos(alpha) = ----------- = %+.4f \n" " ||u|| ||v|| \n\n\n\n\n", dot_R(u,v) / ( norm_R(u) * norm_R(v) )); stop(); clrscrn(); printf(" Q:"); p_mR(Q, S3,P4,C6); printf("\n\n\n\n\n"); stop(); clrscrn(); printf(" Calculate the cosine of the angle" " between vectors U and V: \n\n"); printf(" Qu:"); p_mR(Qu, S3,P4,C6); printf(" Qv:"); p_mR(Qv, S3,P4,C6); printf(" <Qu,Qv> \n" " cos(alpha) = ------------- = %+.4f \n" " ||Qu|| ||Qv|| \n\n\n\n\n", dot_R(Qu,Qv) / ( norm_R(Qu) * norm_R(Qv) )); stop(); clrscrn(); printf(" Orthonormal matrices preserve angles.\n\n" " Calculate the cosine of the angle between" " vectors U and V: \n\n" " <u,v> \n" " cos(alpha) = ----------- = %+.4f \n" " ||u|| ||v|| \n\n\n\n\n", dot_R(u,v) / ( norm_R(u) * norm_R(v) )); printf(" <Qu,Qv> \n" " cos(alpha) = ------------- = %+.4f \n" " ||Qu|| ||Qv|| \n\n\n\n\n", dot_R(Qu,Qv) / ( norm_R(Qu) * norm_R(Qv) )); stop(); f_mR(u); f_mR(v); f_mR(Qu); f_mR(Qv); f_mR(Q); return 0; } /* ------------------------------------ */ /* ------------------------------------ */ Screen output example: Calculate the cosine of the angle between vectors U and V: u: -7 -6 +8 v: -5 -4 +7 <u,v> cos(alpha) = ----------- = +0.9931 ||u|| ||v|| Press return to continue. Q: +0.4819 +0.4615 +0.7448 +0.6196 -0.7806 +0.0828 +0.6196 +0.4216 -0.6621 Press return to continue. Calculate the cosine of the angle between vectors U and V: Qu: -0.1839 +1.0088 -12.1636 Qv: +0.9581 +0.6040 -9.4191 <Qu,Qv> cos(alpha) = ------------- = +0.9931 ||Qu|| ||Qv|| Press return to continue. Orthonormal matrices preserve angles. Calculate the cosine of the angle between vectors U and V: <u,v> cos(alpha) = ----------- = +0.9931 ||u|| ||v|| <Qu,Qv> cos(alpha) = ------------- = +0.9931 ||Qu|| ||Qv|| Press return to continue.