You are on page 1of 1

phys3071-as05-bonanno-42346324.f90 !

23456

Sun Apr 01 20:56:29 2012

100

program Eulermethod !Defining the parameters required for the calculation real :: A, B, C, dA, dB, dC, t, dt, tfinal, ka, kb character (80) :: output_file !Initialising the variables t=0.0 ka = 0.1 kb = 0.1 !Preparing the data format required for the output file format(F6.2, 1X, F6.2, 1X, F6.2, 1X, F6.2) !This begins the program, asking the user to input the !required values write(*,*) "Enter final time" read(*,*) tfinal write(*,*) "Enter step size dt" read(*,*) dt write(*,*) "Enter initial value of A" read(*,*) A write(*,*) "Enter initial value of B" read(*,*) B write(*,*) "Enter intial value of C" read(*,*) C write(*,*) "Now enter the name of the output file" read(*,*) output_file !This opens a new file, with the name specified by the user, !Replacing it if it already exists open(unit=7, file=output_file, action="write",status="replace") !This is the code for the Euler Method. It calculates the !derivatives at each time step, and calculates the new values !for A, B and C. !With each iteration, it writes the values of t, A, B and C !and writes them in the output file, until t reaches tfinal do while (t<=tfinal) dA=-ka*A dB=ka*A-kb*B dC=kb*B A=A+dA B=B+dB C=C+dC t=t+dt write(7,fmt=100) t, A, B, C end do !This closes the output file close(unit=7) end program

You might also like