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

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: c00c.c */ /* ------------------------------------ */ #include "v_a.h" /* ------------------------------------ */ #define RCA RC5 /* ------------------------------------ */ /* ------------------------------------ */ double f( double x) { return(sin(2*x)); } char feq[] = "sin(2*x)"; /* ------------------------------------ */ double g( double x) { return(2*sin(x)*cos(x)); } char geq[] = "2*sin(x)*cos(x)"; /* ------------------------------------ */ /* ------------------------------------ */ void fun(void) { double **A = rsymmetric_mR( i_mR(RCA,RCA),999); double **sin2A = i_mR(RCA,RCA); double **TwosincosA = i_mR(RCA,RCA); double **EVector = i_mR(RCA,RCA); double **EVectorT = i_mR(RCA,RCA); double **EValue = i_mR(RCA,RCA); double **sin2A_EValue = i_mR(RCA,RCA); double **TwosincosA_EValue = i_mR(RCA,RCA); double **T1 = i_mR(RCA,RCA); clrscrn(); printf(" A:"); p_mR(A,S10,P4,C6); eigs_V_mR(A,EVector); transpose_mR(EVector,EVectorT); /* EValue = EVectorT A EVector */ mul_mR(EVectorT,A,T1); mul_mR(T1,EVector,EValue); printf(" sin(2A)"); f_eigs_mR(f,EValue,sin2A_EValue); /* sin2A = EVector sin2A_EValue EVectorT */ mul_mR(EVector,sin2A_EValue,T1); mul_mR(T1,EVectorT,sin2A); p_mR(sin2A,S10,P4,C6); printf(" 2 sin(A) cos(A)"); f_eigs_mR(g,EValue,TwosincosA_EValue); /* TwosincosA = EVector TwosincosA_EValue EVectorT */ mul_mR(EVector,TwosincosA_EValue,T1); mul_mR(T1,EVectorT,TwosincosA); p_mR(TwosincosA,S10,P4,C6); f_mR(A); f_mR(sin2A); f_mR(TwosincosA); f_mR(EVector); f_mR(EVectorT); f_mR(EValue); f_mR(TwosincosA_EValue); f_mR(sin2A_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: sin(x+y) = cos(x)sin(y)+sin(x)cos(y) let x = y sin(x+x) = cos(x)sin(x)+sin(x)cos(x) sin(2x) = 2 cos(x)sin(x) Screen output example: A: -552.0000 -897.0000 -986.0000 -531.0000 -186.0000 -897.0000 +65.0000 +272.0000 -755.0000 -659.0000 -986.0000 +272.0000 -448.0000 +582.0000 -941.0000 -531.0000 -755.0000 +582.0000 +821.0000 -818.0000 -186.0000 -659.0000 -941.0000 -818.0000 +681.0000 sin(2 A) -0.7523 -0.1290 -0.0696 +0.0107 +0.0857 -0.1290 -0.0338 -0.5954 +0.2266 -0.0795 -0.0696 -0.5954 +0.2256 -0.5365 -0.1537 +0.0107 +0.2266 -0.5365 -0.1129 -0.0821 +0.0857 -0.0795 -0.1537 -0.0821 -0.6507 2 sin(A) cos(A) -0.7523 -0.1290 -0.0696 +0.0107 +0.0857 -0.1290 -0.0338 -0.5954 +0.2266 -0.0795 -0.0696 -0.5954 +0.2256 -0.5365 -0.1537 +0.0107 +0.2266 -0.5365 -0.1129 -0.0821 +0.0857 -0.0795 -0.1537 -0.0821 -0.6507 Press return to continue Press X return to stop