Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PROGRAM vct
- IMPLICIT NONE
- INTEGER, ALLOCATABLE, DIMENSION(:) :: mgs
- INTEGER, ALLOCATABLE, DIMENSION(:) :: xps
- INTEGER, ALLOCATABLE, DIMENSION(:) :: yps
- REAL :: fx
- REAL :: fy
- INTEGER :: i
- INTEGER :: j
- INTEGER :: k
- INTEGER :: n
- REAL(3), PARAMETER :: pi = 3.1415926536
- REAL(3), PARAMETER :: e0 = 8.854187817e-12
- ! CHARACTER (LEN=1) :: m1
- fx = 0
- fy = 0
- i = 0
- WRITE(6,*) 'How many charges?'
- READ(5,* ) n
- ALLOCATE(mgs(n))
- ALLOCATE(xps(n))
- ALLOCATE(yps(n))
- DO
- IF (i /= n) THEN
- i=1+i
- WRITE(6,*) 'Enter magnitude of charge number',i
- READ(5,* ) mgs(i)
- WRITE(6,*) 'Enter x-position of this charge (between -10 and 10)'
- READ(5,* ) xps(i)
- WRITE(6,*) 'Enter y-position of this charge (between -10 and 10)'
- READ(5,* ) yps(i)
- CYCLE
- ELSE
- EXIT
- END IF
- END DO
- DO i=-10,10,1
- DO j=-10,10,1
- DO k=1,SIZE(mgs),1
- IF ((ABS(xps(k)-i) /= 0) .AND. (ABS(yps(k)-j) /= 0)) THEN
- fx = fx + (mgs(k)*(xps(k)-i))/(4*pi*e0*(ABS(xps(k)-i))**3)
- CYCLE
- ELSE
- CYCLE
- END IF
- END DO
- DO k=1,SIZE(mgs),1
- IF ((ABS(xps(k)-i) /= 0) .AND. (ABS(yps(k)-j) /= 0)) THEN
- fy = fy + (mgs(k)*(yps(k)-j))/(4*pi*e0*(ABS(yps(k)-j))**3)
- CYCLE
- ELSE
- CYCLE
- END IF
- END DO
- WRITE(6,*) i, j, fx, fy
- END DO
- END DO
- DEALLOCATE(mgs(n))
- DEALLOCATE(xps(n))
- DEALLOCATE(yps(n))
- END PROGRAM vct
Advertisement
Add Comment
Please, Sign In to add comment