Advertisement
Guest User

Euler Method

a guest
May 15th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. !!!PRINCIPAL
  2. program algebra
  3.    
  4.     use algebra_lineal
  5.     use algebra_no_lineal
  6.  
  7.     implicit none
  8.     real(8),allocatable:: U(:)
  9.     integer::n,m,i
  10.     real(8)::tiniciales(2),t,deltat,z
  11.     tiniciales(1)=0.d0
  12.     tiniciales(2)=2.d0
  13.     n=10
  14.     deltat=( tiniciales(2) - tiniciales(1)) / dble(n)
  15.     m=1
  16.     allocate(u(m))
  17.     u=0.d0
  18.     u(1)=(1.d0)/(2.d0)
  19.     open(unit=10, file='resultadosdiez.dat')
  20.     do i=1 ,n
  21.         call Euler ( m, U, t, deltat, FdeU)
  22.         write(10,*)t,U,exacta(t)
  23.         z=dble(i)
  24.         t=z*deltat
  25.     enddo
  26.     deallocate(u)
  27.     close(10)
  28.     n=100
  29.     allocate(u(m))
  30.     u=0.d0
  31.     u(1)=(1.d0)/(2.d0)
  32.     deltat=( tiniciales(2) - tiniciales(1)) / dble(n)
  33.     open(unit=11, file='resultadoscien.dat')
  34.     do i=1 ,n
  35.         call Euler ( m, U, t, deltat, FdeU)
  36.         write(11,*)t,U,exacta(t)
  37.         z=dble(i)
  38.         t=z*deltat
  39.     enddo
  40.     deallocate(u)
  41.     close(11)
  42.  
  43. end program
  44.  
  45. !!!FUNCIONES
  46.  
  47.   function FdeU (m,U,t)
  48.     real(8)::FdeU(1:m)
  49.     real(8), intent(in):: U(1:m), t
  50.     integer, intent(in)::m
  51.     FdeU(1)=U(1) - t**2 +1
  52.   end function
  53.   function exacta(t)
  54.     real(8)::exacta,t
  55.     exacta=(t + 1.d0)**(2.d0) - ((exp (t)) / 2.d0)
  56.   end function
  57.  
  58. !!!EULER
  59.  
  60.       subroutine Euler ( m, U, t, dt, F)
  61.         !*** Interface for the m--dimensional vector valued function F
  62.         interface
  63.         function F ( m, U, t )
  64.         integer, intent(in) :: m
  65.         real(8), intent(in) :: t, U(1:m)
  66.         real(8) :: F (1:m)
  67.         end function F
  68.         end interface
  69.         !*** Dummy arguments specification
  70.         integer, intent(in) :: m
  71.         real(8), intent(in) :: t, dt
  72.         real(8), intent(inout) :: U(1:m)
  73.         !*** U^{n+1} = U^n + dt * F ( U^n, t_n )
  74.         U = U + dt * F ( m, U, t )
  75.         end subroutine Euler
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement