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

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

__NOTOC__ The Maclaurin series of the exponential function is : Exp(A) = Ide + A + (1/2) A2 + (1/6) A3 + ... + 1/(n-1)! A(n-1) Install and compile this file in your working directory. /* ------------------------------------ */ /* Save as : c00d.c */ /* ------------------------------------ */ #include "v_a.h" /* ------------------------------------ */ #define RCA RC4 /* ------------------------------------ */ void fun(void) { double **A = i_mR(RCA,RCA); double **B = i_mR(RCA,RCA); double **ExpA = i_mR(RCA,RCA); double **ExpB = i_mR(RCA,RCA); double **AplsB = i_mR(RCA,RCA); double **ExpAplsB = i_mR(RCA,RCA); r_commute2_mR(A,B,9); add_mR(A,B,AplsB); clrscrn(); printf(" Copy/Paste into the octave window.\n\n"); p_Octave_mR(A, "A", P12); printf(" expm (A)\n\n"); p_Octave_mR(B, "B", P12); printf(" expm (B)\n\n"); stop(); clrscrn(); printf(" Copy/Paste into the octave window.\n\n"); p_Octave_mR(AplsB, "AplsB", P12); printf(" expm (AplsB)\n\n"); printf(" expm (A)*expm (B)\n"); printf(" expm (B)*expm (A)\n\n"); stop(); clrscrn(); Exp_mR(A, ExpA); Exp_mR(B, ExpB); Exp_mR(AplsB, ExpAplsB); printf(" ExpA:"); p_mR(ExpA,S8,P6,C6); printf(" ExpB:"); p_mR(ExpB, S8,P6,C6); stop(); clrscrn(); printf(" Exp(A+B):"); pE_mR( ExpAplsB, S10,P6,C6); printf(" ExpA ExpB:"); mul_mR(ExpA,ExpB,A); pE_mR(A, S10,P6,C6); printf(" ExpB ExpA:"); mul_mR(ExpB,ExpA,A); pE_mR(A, S10,P6,C6); f_mR(A); f_mR(ExpA); f_mR(B); f_mR(ExpB); f_mR(AplsB); f_mR(ExpAplsB); } /* ------------------------------------ */ int main(void) { time_t t; srand(time(&t)); do { fun(); } while(stop_w()); return 0; } /* ------------------------------------ */ /* ------------------------------------ */ Screen output example: Copy/Paste into the octave window. A=[ +0.651229676410,-0.042844371482,+0.109735572993,-0.287314150671; +0.578135767082,+0.078551237862,+0.679891832956,-0.018866033171; -0.220829464815,+0.457464704573,-0.074343208669,-0.226287988476; -0.439114053451,-0.186677981792,-0.698919450592,-0.231944296903] expm (A) B=[ -0.665366299106,+0.065593888084,+0.173117996013,-0.101562674808; +0.216500041694,-0.806237016140,+0.076268748746,-0.210533755400; +0.170408010976,+0.034803770499,-0.719144373990,+0.066358267503; -0.121352197976,-0.176587033764,+0.002992514224,-0.780165526660] expm (B) Press return to continue. Copy/Paste into the octave window. AplsB=[ -0.014136622696,+0.022749516602,+0.282853569006,-0.388876825479; +0.794635808776,-0.727685778279,+0.756160581702,-0.229399788571; -0.050421453839,+0.492268475072,-0.793487582659,-0.159929720973; -0.560466251427,-0.363265015556,-0.695926936368,-1.012109823563] expm (AplsB) expm (A)*expm (B) expm (B)*expm (A) Press return to continue. ExpA: +1.982502 +0.018941 +0.269631 -0.393089 +0.812836 +1.253644 +0.801838 -0.192909 -0.087226 +0.515684 +1.152554 -0.196678 -0.586173 -0.341313 -0.756688 +0.941441 ExpB: +0.528662 +0.037534 +0.088757 -0.050648 +0.114680 +0.459455 +0.045400 -0.100303 +0.085867 +0.016648 +0.495185 +0.025597 -0.069021 -0.082736 -0.007438 +0.470078 Press return to continue. Exp(A+B): +1.100528e+00 +1.201253e-01 +3.132607e-01 -2.801912e-01 +6.556531e-01 +6.358089e-01 +5.275610e-01 -2.370650e-01 +1.255617e-01 +2.691235e-01 +5.878515e-01 -1.102654e-01 -4.789877e-01 -2.693045e-01 -4.492359e-01 +4.870977e-01 ExpA ExpB: +1.100529e+00 +1.201250e-01 +3.132618e-01 -2.801904e-01 +6.556490e-01 +6.358118e-01 +5.275533e-01 -2.370704e-01 +1.255663e-01 +2.691202e-01 +5.878604e-01 -1.102592e-01 -4.789825e-01 -2.693081e-01 -4.492259e-01 +4.871048e-01 ExpB ExpA: +1.100529e+00 +1.201250e-01 +3.132618e-01 -2.801904e-01 +6.556490e-01 +6.358118e-01 +5.275533e-01 -2.370704e-01 +1.255663e-01 +2.691202e-01 +5.878604e-01 -1.102592e-01 -4.789825e-01 -2.693081e-01 -4.492259e-01 +4.871048e-01 Press return to continue Press X return to stop