Tuesday, 15 May 2012

Different results for similar C and Fortran code -


This is an overview of homework (past deadline) for which we Awlrs clear plan for the investigation of a predator-prey Use was ideal. I compare Fortran and C code (given below), and I can not explain why the result is different, when I compare Fortran Code and C code.

C code:

  #include & lt; Stdio.h & gt; // Euler clear float for work FR (float r, float f, float alpha) {returns (2 * r - alpha * r * f); } Float FF (float r, float f, float alpha) {return (-f + alpha * r * f); } Int main () {int n; Float alpha, initR, initf, bigR, h; / * Data Setup * / Alpha = 0.001; InitR = 15; InitF = 22; N = 50; BigR = 400; H = 0.01; Float R, F, R1, F1; Int i; R0 = initR; F0 = initF; For (I = 0; i & lt; N; i ++) (R1 = R + H * FR (R, F, Alpha); F1 = FHH * FF (R, F0, alpha); printf ("% d \ t% f \ t% f \ n", I, R1, F1); R = R1; F0 = F1;} Return 0;}   

There are now similar to Fortran version, initialization parameters above C version.

 ! Ilr Akspilit Sbtrut Ilrs_ Aksplitik (IITR, Anaitif, N, alpha, H) real Term: R, F0, R1, F1, IITF, NITR, Alpha, H INTEGER I, NR = IITR F 0 = IITF I = 1, NR1 = R + H * FR (R, F, Alpha) F1 = FHHFF (RFF, alpha) print *, I, R1, F1R R 0 F 1 F 1 R 0 R 1 F 0 = F 1 and end Sbbutin Ilrs_ Aksplat! Ielar = 2 * R - alpha * R * F FR = R Andanshn FR FAR Fiaraar FAR FAR FR FRL Faarf FF (R, F, alpha) REL, Inntkent (RA) :: R Alpha Real, intent (INOUT) :: FF = F + alpha * R F FF = F & FF program Fif Prog Using the program does not apply to normal Samany_wahnon INTEGER :: N Reyl :: Alpha, Initar, Initf, H alpha = 0.001 initR = 15 initF = 22 N = 50 H = 0.01 * Print, "users clear pattern:" Call Ilrs_ Akspliytik (initR, initF, N, alpha, H) and programs to solve   

the result, a snapshot of the results of C code:

  0 15.2 9 6700 21.783300 1 15.599301 21.568800 2 15.907923 21.356476 3 16.222683 21.146309 4 16.543707 20.938276 5 16.871117 20.732357 6 17.205042 20.528532 7 17.545610 20.326778 8 17.892956 20.127077 9 18.247213 19.929407 10 18.608521 19.733749 Contact with FORTRAN CODE Rinam:  
  0 29.9666996 -21.5607319 1 61.1852989 20.4571381 2 122.330109 -18.1591854 3 24 9.35044 9 13.8127756 4 500.20 9 25 9 -7 .04162502 5 1013.98022 -2.80275159 E -02 6 2048.26880 -2.91000 9 59 e -02 7 4137.56299 -9.10123810 e -02 8 8358.25781 -0668782473 9 16889.3262 -10.6198158 10 34297.5 9 77 -353.508148   

I see why this deviation? I'm using gfortran (v4.7.2), and it's running Arch Linux on my laptop on Intel i7.

Edit:

It's OK.

 <0> Actual function F (R, F, Alpha) Actual, VALUE :: F, Alpha REAL, VALUE :: RR = 2 * R - alpha * RF = FF = R and function FR   

Fortran subcontinent FF And FR revises their arguments, while do not do the equivalent.

No comments:

Post a Comment