Advertisement
Guest User

Untitled

a guest
May 12th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program main
  2.     use utilidades
  3.  
  4.     real(8) :: a, b, n, h
  5.     real(8) :: y_new, y_old
  6.     real(8) :: t_new, t_old
  7.  
  8.     ! ESTABLECEMOS LAS CONDICIONES INICIALES DEL TRAPECIO
  9.     a = 0
  10.     b = 1
  11.     n = 100
  12.     h = (b-a)/n
  13.  
  14.     ! CONDICIONES INICIALES PARA LA ECUACIÓN DIFERENCIAL
  15.     y_old = 2
  16.  
  17.     ! HACEMOS UN BUCLE n VECES, QUE ASIGNE VALORES A t_new,
  18.     ! t_old, y_new, Y HAGA QUE EL NUEVO y_old SEA EL ACTUAL
  19.     ! y_new
  20.  
  21.     ! TAMBIÉN ESCRIBIMOS EN UN ARCHIVO .TXT LOS VALORES DE
  22.     ! t Y DE y(t)
  23.  
  24.     open(10, file="datos.txt")
  25.  
  26.     do i = 1, n
  27.         t_new = a + i*h
  28.         t_old = a + (i-1)*h
  29.  
  30.         y_new = getNewY(t_new, t_old, y_old, h)
  31.  
  32.         write(10, *) y_new, t_new
  33.  
  34.         y_old = y_new
  35.     end do
  36.  
  37. end
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.     function f(t) result(resultado)
  50.         real(8), intent(in) :: t
  51.         real(8) :: resultado
  52.         resultado = !FUNCIÓN T, AQUÍ
  53.     end function
  54.  
  55.  
  56.     function g(t) result(resultado)
  57.         real(8), intent(in) :: t
  58.         real(8) :: resultado
  59.         resultado = !FUNCIÓN G, AQUÍ
  60.     end function
  61.  
  62.     function getNewY(t_new, t_old, y_old, h) result(resultado)
  63.         real(8), intent(in) :: t_new, t_old, y_old, h
  64.         real(8) :: resultado
  65.  
  66.         resultado = &
  67.         1/(1- h/2 * f(t_new)) * (y_old * (1 + h/2 * f(t_old)) + h/2 * (g(t_old) + g(t_new)))
  68.     end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement