Prev: Selecting the first element of a array returned by pack()
Next: size of a derived type containing pointers...
From: ajay on 25 Mar 2010 01:55 how can we implement this in fortran 77. i know there is intrinsic recursive function in fortran 90/95. function func(x,y) .... .... if ( y.lt.1.0d0 ) then func = ........ elseif ( y.gt.1.0d0 ) then func = something/func(x,-y) end if end function waiting for the reply..... thanking you.....
From: m_b_metcalf on 25 Mar 2010 04:07 On Mar 25, 6:55 am, ajay <ajay.rawa...(a)gmail.com> wrote: > how can we implement this in fortran 77. > i know there is intrinsic recursive function in fortran 90/95. > > function func(x,y) > ... > ... > if ( y.lt.1.0d0 ) then > > func = ........ > > elseif ( y.gt.1.0d0 ) then > > func = something/func(x,-y) > > end if > > end function > > waiting for the reply..... > thanking you..... Basically, you can't. But if you just add the recursive keyword and use a modern compiler, it will work. Regards, Mike Metcalf
From: glen herrmannsfeldt on 25 Mar 2010 05:57 ajay <ajay.rawat83(a)gmail.com> wrote: > how can we implement this in fortran 77. > i know there is intrinsic recursive function in fortran 90/95. > function func(x,y) (snip) > func = something/func(x,-y) The majority of recursive functions are better written using loops, at least for ones that call themselves directly. Without the rest of the program, it is hard to be more specific. One case that does work better as recursion is the recursive descent compiler. In that case, the recursion is mostly indirect, and doesn't follow a simple pattern. -- glen
From: Charles on 25 Mar 2010 06:07 > "m_b_metcalf" <michaelmetcalf(a)compuserve.com> wrote in message > On Mar 25, 6:55 am, ajay <ajay.rawa...(a)gmail.com> wrote: > > how can we implement this in fortran 77. > > i know there is intrinsic recursive function in fortran 90/95. > > [snip] > Basically, you can't. But if you just add the recursive keyword and > use a modern compiler, it will work. > > Regards, > > Mike Metcalf You can always transform any set of recursive calls into iteration - this was proved by mathematicians years ago. Without seeing the rest of the code, I cannot give a direct translation, but if it was along the lines of (e1 and e2 stand for expressions in x, y, and constants) real function f( x, y ) real x real y if( y .lt. 1.0d0 ) then f = e1(x,y) elseif( y.gt. 1.0d0 ) then f = e2(x,y)/f(x,-y) else ! y .eq.1.0d0, what to do ? .... endif end then one possible transformation would be real function f( x, y ) real x real y if( y .lt. 1.0d0 ) then f = e1(x,y) elseif( y.gt. 1.0d0 ) then f = e2(x,y)/e1(x,-y) else ! y .eq.1.0d0, what to do ? .... endif end It all depends on what is done before the if, and what the expressions e1 and e2 look like. Charles
From: ajay on 25 Mar 2010 07:23 ---------- Forwarded message ---------- From: "Charles" <C.Sand...(a)DeleteThis.Bom.GOV.AU> Date: Mar 25, 3:07 pm Subject: calling a recursive function in fortran 77 ? To: comp.lang.fortran > "m_b_metcalf" <michaelmetc...(a)compuserve.com> wrote in message > On Mar 25, 6:55 am, ajay <ajay.rawa...(a)gmail.com> wrote: > > how can we implement this in fortran 77. > > i know there is intrinsic recursive function in fortran 90/95. [snip] > Basically, you can't. But if you just add the recursive keyword and > use a modern compiler, it will work. > Regards, > Mike Metcalf You can always transform any set of recursive calls into iteration - this was proved by mathematicians years ago. Without seeing the rest of the code, I cannot give a direct translation, but if it was along the lines of (e1 and e2 stand for expressions in x, y, and constants) real function f( x, y ) real x real y if( y .lt. 1.0d0 ) then f = e1(x,y) elseif( y.gt. 1.0d0 ) then f = e2(x,y)/f(x,-y) else ! y .eq.1.0d0, what to do ? .... endif end then one possible transformation would be real function f( x, y ) real x real y if( y .lt. 1.0d0 ) then f = e1(x,y) elseif( y.gt. 1.0d0 ) then f = e2(x,y)/e1(x,-y) else ! y .eq.1.0d0, what to do ? .... endif end It all depends on what is done before the if, and what the expressions e1 and e2 look like. Charles thank you charles ...... your suggestion is quiet good, but as you rightly pointed out the e1 and e2 are not simple analytic function they are some numerical values obtained from some quadrature. i guess i'll metcalf solution anyways thanks to everyone
|
Next
|
Last
Pages: 1 2 3 4 5 6 7 Prev: Selecting the first element of a array returned by pack() Next: size of a derived type containing pointers... |