Silverfrost Forums

Welcome to our forums

Calcul an integrale with winio+and fortran95

1 Jan 2009 9:51 #4150

Good morning I thank LitusSaxonicum for his help to do my program Now i have this program WINAPP INCLUDE<windows.ins> DOUBLE PRECISION A,B,somme CHARACTER*50 s COMMON A,B,somme,N INTEGER i,w,N EXTERNAL TRAP A=0.0E0 B=0.0E0 somme=0.0E0 N=0 i=winio@('%ca[Calcule une integrale]&') s='{integral A;B} (X+1)dx=somme' w=winio@('%ob%eq@%cb&',s,0,0) w=winio@('&') i=winio@('%5tl&',1,2,3,4,5) i=winio@('%ffA=%ta&') i=winio@('%rf&',A) i=winio@('%ffB=%ta&') i=winio@('%rf&',B) i=winio@('%ffsomme=%ta&') i=winio@('%rf&',somme) i=winio@('%ffN=%ta&') i=winio@('%rd&',N) i=winio@('%ta%`^12bt[INTEGRATION]',TRAP) END

FUNCTION F(T) REAL(SELECTED_REAL_KIND(15,307))T

F=T+1 RETURN END INTEGER FUNCTION TRAP()

INTEGER I,N COMMON A,B,somme,N REAL (SELECTED_REAL_KIND(15,307))X,B,A,somme

DX=(B-A)/N TRAP=(F(A)+F(B))/2 X=A DO 10 I=1,N-1 X=X+DX TRAP=TRAP+F(X) 10 CONTINUE TRAP=TRAP*DX somme=TRAP CALL window_update@(somme) RETURN END The program is running and gives results I have run many examples but results are always lower than the right result With the example i send you the result is 175 for 181.5 Your very truly

1 Jan 2009 11:13 #4151

Part of the problem is that TRAP is declared as INTEGER when it should be REAL.

1 Jan 2009 7:13 #4152

To amplify Paul's comments: your use of Integer function TRAP in a callback is OK, but it should return integer 1 or 0. In that function, you should not be using the variable TRAP as if it was a general purpose real variable - use something else. In fact as a general rule I make my callback function names something I wouldn't accidentally use as anything else.

Glad to have helped the previous time.

Eddie

Please login to reply.