[Tutor] Do loop in Python

stm atoc stm.at.oc at googlemail.com
Fri Nov 25 12:13:44 CET 2011


regarding to the last email:


what  I am trying to do is seeing the variation of 'nu' over (changes of)  'z'.

My concern is how to arrange this!

Basically, I am not able to define the variation of  nu by z ( 1 to
200). I am looking for a statement to show the changes of 'nu' for
each step of z (as height).
On the other hand, for each step, 'h' is supposed to be subtracted
from 'z' (like: 200-10, 190-10...) as well, at least 10 times (which
was trying to be defined as N)!
I hope this is somehow clear....

Thanks in advance,
Sue
- Show quoted text -
On Fri, Nov 25, 2011 at 10:16 AM, stm atoc <stm.at.oc at googlemail.com> wrote:
> Hi there,
>
> I am a new python user.
> I have  a question regarding  do loop.....
>
> This is a simple program that I have written:
>
> -----------------
> N=10
> h=10.0 # [micrometer]
> z=-200.0 # [micrometer]
> num = 0.05 #m**2/s
> dz = 1.0
> nuh=[]
> tmax=3600
> dt=20.
> nu=[]height = arange(z*dz,0,dz)
>
> outfile=open('nu.dat','w')
> outfile.write('height, nu, nuh')
>
> for z,when in enumerate(height):
>   for h in range(10):
>       for N in range(10):
>           for z in range((N-z)+(N-h)):
>
>               nuh.append(0.01 * exp(-0.05*(z+200.0))*dz) #turbulence
> diffusivity m**2/s
>               nu.append(num + nuh[z])
>
> -----------------------
> What I like to do with this program is do loop like the fortran
> version of  as follows:
>
> do i = 2, N
>  z(i) = z(i-1) +h(i-1)
>
> end do
>
> write(0,*) 'z ', z(1:N)
> write(0,*) 'when ', 'nu ','Conc '
>
>
> do i= 1, N
>
>  nuh(i)= 0.01d0*exp(-0.005d2*(z(i)+200)) ! turbulence diffusivity m**2/s
>  nu(i)= num(1) + nuh(i)
>
>
> end do
>
> ----------
> My problem is I am notable have the curve in the output plot as I have
> as a result of  FORTRAN program. What happens is just having a
> straight line....!
> the whole problem is in z part, which is supposed to be changed and i
> do not see it!
>
>  So, would it be possible to take a look at it please. any suggestion
> would greatly appreciated.
>
> Thank you,
> Sue
>


More information about the Tutor mailing list