Fortran 95 Nesting of loops (beginner) -


i new fortran 95 , trying grip on nested loops. below small code nested loop. inner loop secant method calculates root of function "z+x1**2-612" , saves x0 via iteration. istep howmany iterations took. loop on own works. want repeat loop various "z". example 300 360 increments of 10.

if run code, z vary 300 360 should, keep getting x0 300 (i.e. square root of 312).

is there has experience nested loops (not secant method, since inner loop works), can tell me why print out 300 360 well, x0 if z never changes 300? browsed through forum, , found similar issues had variable declarations placed wrongly, doesn't seem problem in case.

hereunder code, hope can me. bit old start learn programming, never late guess!

program doloop2   implicit none   integer :: istep,z   real :: a,b,dl,dx,x0,x1,d,x2    dl = 1.0e-06     = 10 !lower guess   b  = 20 !upper guess   dx = (b-a)/10.0 !stepsize   x0 = (a+b)/2.0    istep = 0 !first iteration   x1 = x0+dx  z=300,360,10 while (abs(dx).gt.dl)     d  = (z+x1**2-612)-(z+x0**2-612)     x2 = x1-(z+x1**2-612)*(x1-x0)/d     x0 = x1     x1 = x2     dx = x1-x0     istep = istep+1 end print *,'temperature=',z,', xzero= ',x0,'iterations=',istep end  end program doloop2 

do need have of initializations inner loop repeated before loop redone? i.e., relocated inside first loop, before second loop. example, first execution of inner loop change value of dx, effect second execution of loop.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -