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

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 RCA RC5 /* ------------------------------------ */ /* ------------------------------------ */ double f( double x) { return(cos(2*x)); } char feq[] = "cos(2*x)"; /* ------------------------------------ */ double g( double x) { return(2*cos(x)*cos(x)-1); } char geq[] = "2*cos(x)**2)-1"; /* ------------------------------------ */ /* ------------------------------------ */ void fun(void) { double **A = rsymmetric_mR( i_mR(RCA,RCA),999.); double **cos2A = i_mR(RCA,RCA); double **TwocosA_P2_mns1 = i_mR(RCA,RCA); double **EVector = i_mR(RCA,RCA); double **EVectorT = i_mR(RCA,RCA); double **EValue = i_mR(RCA,RCA); double **cos2A_EValue = i_mR(RCA,RCA); double **TwocosA_P2_mns1_EValue = i_mR(RCA,RCA); double **T1 = i_mR(RCA,RCA); clrscrn(); printf(" A:"); p_mR(A,S10,P4,C6); stop(); clrscrn(); eigs_V_mR(A,EVector); transpose_mR(EVector,EVectorT); /* EValue = EVectorT A EVector */ mul_mR(EVectorT,A,T1); mul_mR(T1,EVector,EValue); printf(" cos(2 A)"); f_eigs_mR(f,EValue,cos2A_EValue); /* cos2A = EVector cos2A_EValue EVectorT */ mul_mR(EVector,cos2A_EValue,T1); mul_mR(T1,EVectorT,cos2A); p_mR(cos2A,S10,P4,C6); printf(" 2cos(A)**2-1"); f_eigs_mR(g,EValue,TwocosA_P2_mns1_EValue); /* TwocosA_P2_mns1 = EVector TwocosA_P2_mns1_EValue EVectorT */ mul_mR(EVector,TwocosA_P2_mns1_EValue,T1); mul_mR(T1,EVectorT,TwocosA_P2_mns1); p_mR(TwocosA_P2_mns1,S10,P4,C6); f_mR(A); f_mR(cos2A); f_mR(TwocosA_P2_mns1); f_mR(EVector); f_mR(EVectorT); f_mR(EValue); f_mR(TwocosA_P2_mns1_EValue); f_mR(cos2A_EValue); f_mR(T1); } /* ------------------------------------ */ int main(void) { time_t t; srand(time(&t)); do { fun(); } while(stop_w()); return 0; } /* ------------------------------------ */ /* ------------------------------------ */ Let's check the equations: We know that: cos(x+y) = cos(x)cos(y)-sin(x)sin(y) let x = y cos(x+x) = cos(x)cos(x)-sin(x)sin(x) cos(2x) = cos(x)**2-sin(x)**2 cos(x)**2 + sin(x)**2 = 1 sin(x)**2 = 1-cos(x)**2 cos(2x) = cos(x)**2-(1-cos(x)**2) cos(2x) = 2*cos(x)**2-1 Screen output example: A: +856.0000 -81.0000 +972.0000 -635.0000 -332.0000 -81.0000 -687.0000 -161.0000 +565.0000 +329.0000 +972.0000 -161.0000 +318.0000 -28.0000 +498.0000 -635.0000 +565.0000 -28.0000 +856.0000 -790.0000 -332.0000 +329.0000 +498.0000 -790.0000 +826.0000 Press return to continue. cos(2 A) +0.3238 +0.1849 +0.0061 +0.1818 -0.4218 +0.1849 +0.0638 -0.2402 +0.0712 +0.1951 +0.0061 -0.2402 +0.1008 +0.1617 -0.1561 +0.1818 +0.0712 +0.1617 -0.0239 -0.1967 -0.4218 +0.1951 -0.1561 -0.1967 +0.3976 2 cos(A)**2-1 +0.3238 +0.1849 +0.0061 +0.1818 -0.4218 +0.1849 +0.0638 -0.2402 +0.0712 +0.1951 +0.0061 -0.2402 +0.1008 +0.1617 -0.1561 +0.1818 +0.0712 +0.1617 -0.0239 -0.1967 -0.4218 +0.1951 -0.1561 -0.1967 +0.3976 Press return to continue Press X return to stop