Moderators: kostas213, pao132003, niovgalto_psema, kamari, sos
do while (t(i) .lt. tf)
write(1,*) i, t(i), x(i), y(i)
i=i+1
t(i)=t(i-1)+dt
x(i)=x(i-1)+dt*(2.0*x(i-1)-0.5*x(i-1)*y(i-1))
y(i)=y(i-1)+dt*(0.25*x(i-1)*y(i-1)-0.6*y(i-1))
enddo
C CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C File triangle.f
C Motion of a free particle in triangle (x=0,y=0,x+y=1)
C Use integration with time step dt: x = x + vx*dt y=y+vy*dt
C ------------------------------------------------------------
program triangle2D
implicit none
C ------------------------------------------------------------
C Declaration of variables
real*8 x0,y0,v0x,v0y,t0,tf,dt,t,x,y,vx,vy,vx_old
integer i,nx,ny,nt
C ------------------------------------------------------------
C Ask user for input:
print *,'# Enter x0,y0,v0x,v0y:'
read(5,*)x0,y0,v0x,v0y
print *,'# x0= ',x0,' y0= ',y0,' v0x= ',v0x,' v0y= ',v0y
if(x0 .lt. 0.0) stop 'illegal value of x0<0'
if(y0 .lt. 0.0) stop 'illegal value of y0<0'
if(y0 .gt. (-x0+1.0D0))
$ stop 'illegal value (x0,y0): outside triangle'
if(v0x**2+v0y**2.eq. 0.0 ) stop 'illegal value of v0 = 0.'
print *,'# Enter t0,tf,dt:'
read(5,*)t0,tf,dt
print *,'# t0= ',t0,' tf= ',tf,' dt= ',dt
C ------------------------------------------------------------
C Initialize
i = 0
nx = 0
ny = 0
nt = 0
t = t0
x = x0
y = y0
vx = v0x
vy = v0y
open(unit=11,file='triangle.dat')
C ------------------------------------------------------------
C Compute:
do while(t .le. tf)
write(11,*)t,x,y,vx,vy
i = i + 1
t = t0 + i *dt
x = x + vx*dt
y = y + vy*dt
if(x .le. 0.0D0) then
vx = -vx
nx = nx + 1
endif
if(y .le. 0.0D0) then
vy = -vy
ny = ny + 1
endif
if(y .ge. (-x+1.0D0))then
vx_old = vx
vx = -vy
vy = -vx_old
nt = nt + 1
endif
enddo
close(11)
print *,'# Number of collisions:'
print *,'# nx= ',nx,' ny= ',ny,' nt= ',nt
end
1/2rizax wrote:Νικ, έτσι από περιέργεια μπορείς να παρεθέσεις τον κώδικά σου; Μήπως, πχ, για τη σύγκρουση με τη διαγώνιο έγραψες
vx = -vy
vy = -vx
το οποίο δεν είναι σωστό γιατί αναθέτει στη vx την τιμή -vy και αφήνει την vy ως έχει;
Την εναλλαγή την κάνεις βάζοντας καινούρια μεταβλητή ή με κάποιο κολπάκι του στυλ:
vx=vx+vy
vy=vx-vy
vx=vx-vy
vx=-vx
vy=-vy
Users browsing this forum: Google [Bot] and 1 guest