- #1
joseph2015
- 14
- 2
New user has been reminded to use the Template when posting schoolwork problems
I am trying to solve the following first order ODE using a simple Fortran code :
$$ ds/dt=k_i * \sqrt{v}$$
where both (ki) and (v) are variables depending on (h) as follows
$$ k_i=\sqrt{χ/h^2}$$
$$v= \mu h$$
where (μ) and (χ) are constants. (the arbitrary values of each of them can be seen from the code attached).
Note: h changes from 100 to 1 with -1 reduction
Now after writing the code, I would like to plot (s) as a function of (h). but what I will get is not a single plot, but a series of plots depending on the number of timesteps. the issue has to do with loops, but I am not sure how to get a single plot of (s) against (h) as it grows over a period of time.
$$ ds/dt=k_i * \sqrt{v}$$
where both (ki) and (v) are variables depending on (h) as follows
$$ k_i=\sqrt{χ/h^2}$$
$$v= \mu h$$
where (μ) and (χ) are constants. (the arbitrary values of each of them can be seen from the code attached).
Note: h changes from 100 to 1 with -1 reduction
Now after writing the code, I would like to plot (s) as a function of (h). but what I will get is not a single plot, but a series of plots depending on the number of timesteps. the issue has to do with loops, but I am not sure how to get a single plot of (s) against (h) as it grows over a period of time.
Fortran:
program height
implicit none
double precision ki, t, v, s, a, x, tend, dt
integer count,h,nstep
real mu
REAL, PARAMETER :: Pi = 3.1415927
tend = 100
dt = 10
nstep = tend/dt
write(*,*) 'end time for the integration: ', tend
write(*,*) 'integration time step: ', dt
write(*,*) 'number of time steps: ', nstep
open(30, file='height.agr')
x = 1.99
s = 1.0e-2
mu = 2.34
t = 0.0
write(30,*) s, real(h*1.8e+4)
! START to Integrate.
write(*,*) 'Start time integration (', nstep, ' steps) ...'
do count = 1, nstep
! update the time
t = t + dt
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
do h =100,1,-1
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
v =mu*h
ki =sqrt((x)/h**2)
a = ki*sqrt(v)
s = s+dt*a
write(30,*) s, real(h)
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
end do
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
end do
write(*,*) 'end'
close(30)
100 format(d14.8,1x,d14.8)
end program height
Attachments
Last edited: