Math. Math. 455-01, Spring, 1997 Examples

Math. Math. 455-01, Spring, 1997 Examples

/January 21 (Machine constants) / January 30 (Newton iteration program)/
/March 18 (Automatic differentiation)/ April 2 (ODE's)/
This is a set of eamples given in class.
Day 2 (Tuesday, January 21)
This Fortran 90 program:
	double precision x
	write(*,*) digits(x)
	write(*,*) epsilon(x)
	write(*,*) huge(x)
	write(*,*) maxexponent(x)
	write(*,*) minexponent(x)
	end    
	
gives the following output:
	interval% f90 tp.f90 -o tp
	interval% tp
	 53
	   2.2204460492503131E-16
	   1.7976931348623157E+308
	 1024
         -1021
	interval%
	 

Day 5 (Thursday, January 30)
The following is a simple Fortran 90 program to do Newton's iteration.

program simple_newton_method
   implicit none

   double precision x, y, tol
   integer i

   write(*,*) 'input initial guess:'
   read(*,*) y
   write(*,*) 'input tolerance:'
   read(*,*) tol
   i=0
   do i = 1,20
     x = y
     y = x - f(x)/fp(x)
     write(*,'(1x,a,1x,i3,2(1x,d24.16))') 'i, old x, new x:', i, x, y
     if(abs(y-x) < tol) exit
   end do

contains

   function f(x) result(value)
      double precision x, value
      value = tan(x) - x
   end function f
     
   function fp(x) result(value)
      double precision x, value
      value = 1d0/cos(x)**2 -1d0
   end function fp

end program simple_newton_method
March 18
If the module automatic_differentiation.f90 and the module test_automatic_differentiation.f90 are compiled together, then the following results:
interval% f90 test_automatic_differentiation.f90 automatic_differentiation.o   
interval% a.out
X =    0.2000E+01
X**2 + X =    0.6000E+01
DERIVATIVE OF X**2 + X =    0.3000E+01
interval%