- #1

ksx2098

- 1

- 0

## Homework Statement

in fortran 90 write a program to using the euler scheme to solve the differential equation for decay of a radioactive substance

dx/dt = -j*x

solving the equation we get

x = e^(-j*t)

following info is given

**2. Homework Equations and values**

t0 = 0.0

tF = 10.0

tStep = 0.1

x(0) = 1+0i

j = 3.0

## The Attempt at a Solution

Code:

```
PROGRAM EULER
!
INTEGER :: I,N
REAL :: t, x
REAL, PARAMETER :: t0 = 0.0, tF = 10.0, tStep = 0.1, j = 3.0
!
!Calc N
!
N = INT((tF-t0)/tStep + SPACING((tF-t0)/tStep)) + 1 ! trip count
!
!set initial values
!
t = t0
x = 0.0
!
!Calculate x with time
!
DO I + 1, N+1
PRINT *, t, x
x = x + tStep * f(x,t)
t = t + tStep
ENDDO
!
END PROGRAM EULER
!
FUNCTION f(x,t)
!
REAL :: t, x
REAL, PARAMETER :: j = 3.0
!
f = EXP( -1.0 * j * t)
!
END FUNCTION f(x,t)
```

no errors upon compiling

my x value ends up being 2*t

i think the problem is in the DO loop