Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program main
- use utilidades
- real(8) :: a, b, n, h
- real(8) :: y_new, y_old
- real(8) :: t_new, t_old
- ! ESTABLECEMOS LAS CONDICIONES INICIALES DEL TRAPECIO
- a = 0
- b = 1
- n = 100
- h = (b-a)/n
- ! CONDICIONES INICIALES PARA LA ECUACIÓN DIFERENCIAL
- y_old = 2
- ! HACEMOS UN BUCLE n VECES, QUE ASIGNE VALORES A t_new,
- ! t_old, y_new, Y HAGA QUE EL NUEVO y_old SEA EL ACTUAL
- ! y_new
- ! TAMBIÉN ESCRIBIMOS EN UN ARCHIVO .TXT LOS VALORES DE
- ! t Y DE y(t)
- open(10, file="datos.txt")
- do i = 1, n
- t_new = a + i*h
- t_old = a + (i-1)*h
- y_new = getNewY(t_new, t_old, y_old, h)
- write(10, *) y_new, t_new
- y_old = y_new
- end do
- end
- function f(t) result(resultado)
- real(8), intent(in) :: t
- real(8) :: resultado
- resultado = !FUNCIÓN T, AQUÍ
- end function
- function g(t) result(resultado)
- real(8), intent(in) :: t
- real(8) :: resultado
- resultado = !FUNCIÓN G, AQUÍ
- end function
- function getNewY(t_new, t_old, y_old, h) result(resultado)
- real(8), intent(in) :: t_new, t_old, y_old, h
- real(8) :: resultado
- resultado = &
- 1/(1- h/2 * f(t_new)) * (y_old * (1 + h/2 * f(t_old)) + h/2 * (g(t_old) + g(t_new)))
- end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement