Silverfrost Forums

Welcome to our forums

Approximating time gradient

4 Apr 2011 11:26 #8016

Hello,

I have a two-column discrete data file with 10,000 rows. The first column is the time (t) and the second is the velocity data (v) where time increment, Delta-T = 0.0001. I am trying to find the time gradient of the velocity (dv/dt). Can someone help me with the coding below? Many thanks!

OPEN (UNIT=100, FILE=data.txt, STATUS='OLD', ACTION='READ', IOSTAT=ierr) 
		DO i = 1, size(y)
			READ (3,*,IOSTAT=ierr) xdummy, vel(i)  
			if (ierr /=0) exit
	END DO

    n=i-1

tgrad = 0.

DO i = 1,n
tgrad = tgrad+(vel(i+1)-vel(i))/(0.0001)
if (i>n) exit
ENDDO

write(*,'Time gradient is ') tgrad/n*0.0001

CLOSE(UNIT=100, FILE=data.txt, STATUS='OLD', ACTION='WRITE', IOSTAT=ierr) 
5 Apr 2011 12:32 #8026

Isn't the answer to the second DO loop you have coded simply

tgrad = (vel(n+1)-Vel(1)) / 0.0001

Also, does dv/dt ( = (vel(i)-vel(i-1)) / (xdummy(i)-xdummy(i-1)) ) vary with I ?

Assuming it does, you can use a forward difference calculation, in each time step to calculate an estimate of x(i)

x(i) = x(i-1) + (v(i)+v(i-1))/2 * dt + (a(i)+a(i-1))/4 * dt2 ( x = x0 + vel * dt + acc /2 *dt2 )

You can vary the calculation, depending on the way you estimate acceleration (tgrad(i)) varying over dt. It's an interesting change to the forward difference equations.

John

Please login to reply.