- #1

ulfaazmi

- 17

- 1

Anybody can help me?? The problem is when the value of (r1o = r, and r2o=r), the result will be infinite,,,what the the probably test for this case?? I can't test floating point numbers for equality ( if r == 0.5 and r == -0.5). But, when running this program without test floating point, it is success. however, the result is not true because it should be infine value or missing.

This is my code :

<Moderator's note: code tags added>

Thank you.

This is my code :

Fortran:

```
Program EfieldEpotential
implicit none
integer,parameter :: ikind = selected_real_kind(p=15)
real (kind=ikind)::E1,E2,E,V,V1,V2
real :: k,r1o,r2o,q1,q2,r,r1,r2
integer :: i,n=100
! initial position
r1o = -0.5
r2o = 0.5
q1 = -1 ! the charge at r1o
q2 = 1 ! the charge at r2o
k = 9E+9
do i = 1,n
r = -2.1 + real(i)*0.1
r1 = abs(r1o-r)
r2 = abs(r2o-r)
E1 = k*q1/r1**2
E2 = k*q2/r2**2
E = E1+E2
V1 = k*q1/r1
V2 = k*q2/r2
V = V1+V2
if ( r>2.1) then
stop 'Program End'
else
write(*,30) r,E,V
30 format(7x,f8.2,8x,E15.7,8x,E15.7)
end if
end do
End
```

Thank you.

Last edited by a moderator: