Advertisement
Thomas_Lillieskold

Euler Forward method

Mar 11th, 2023
1,263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Fortran 4.18 KB | Science | 0 0
  1. !Este Programa fue realizado por Lillieskold, Thomas Enrique
  2. !Instituto Universitario Aeronautico - 2023
  3. !Docentes: Giovacchini, Juan Pablo; Sacco, Carlos
  4. !Asignatura: Calculo Numerico
  5. !-------------------------------------------------------------------------------
  6.  
  7. !----------------DECLARACION DE VARIABLES PARA Euler-----------------------------
  8. MODULE Data_Euler
  9. REAL(8),PARAMETER::t_min=0.d0
  10. REAL(8),PARAMETER:: t_max=2.d0
  11. REAL(8),PARAMETER:: V_0=1.d0
  12. REAL(8),PARAMETER:: k=0.1
  13. INTEGER,PARAMETER:: dim=(t_max-t_min)/k
  14. END MODULE Data_Euler
  15.  
  16.  
  17. !--------------------------------------INICIO DEL MAIN PROGRAM-----------------------------------------------------------------------------
  18. Program Euler_Forward
  19. USE Data_Euler
  20. Implicit none
  21.  
  22. REAL(8),DIMENSION(dim)::aprox_1
  23. REAL(8),DIMENSION(2*dim)::aprox_2
  24. REAL(8),DIMENSION(4*dim)::aprox_3
  25.  
  26.  
  27. !CALL Euler(aprox_1,k,dim)
  28. CALL Euler(aprox_2,k/2.d0,2*dim)
  29. !CALL Euler(aprox_3,k/4.d0,4*dim)
  30.  
  31. CALL Error_Global(aprox_2,k/2.d0)
  32.  
  33. !CALL Cociente_con_exacta(aprox_1,aprox_2)
  34.  
  35. !CALL Cociente_sin_exacta(aprox_1,aprox_2,aprox_3)
  36.  
  37. END PROGRAM
  38.  
  39. !---------------------------------------FINAL DEL MAIN PROGRAM------------------------------------------------------------------------------
  40.  
  41.  
  42.  
  43. !---------------------------------------SUBRUTINA EULER-------------------------------------------------------------------------------------
  44. SUBROUTINE Euler(aprox,Inc,ext)
  45. USE Data_Euler
  46. Implicit none
  47. REAL(8) v_n,v_o,func,t_i,Inc
  48. INTEGER ext
  49. REAL(8),DIMENSION(ext)::aprox
  50. Integer Iter,i
  51.  
  52. v_o=v_0
  53. t_i=t_min
  54. iter=0
  55.  
  56.     OPEN(3,FILE="Write_outs_k=0.1")
  57.     PRINT*, "      Iter    T_i                      v_n"
  58.     DO i=1,ext,1
  59.         iter=iter+1
  60.         aprox(i)=v_o
  61.         v_n = v_o + Inc * func(v_o,t_i)
  62.         Write(3,*) t_i,aprox(i)
  63.         PRINT*, Iter,t_i,aprox(i)
  64.         v_o=v_n
  65.         t_i=t_i+Inc
  66.     END DO
  67.         PRINT*, "------------------------------------------------------------------------------------------------------"
  68. END SUBROUTINE
  69.  
  70. REAL(8) FUNCTION func(y,x)
  71. Implicit none
  72. REAL(8) y,x
  73.     func=-1.d0*y+ sin(2.d0*dacos(-1.d0)*x)  !Esta funcion es la que acompaña a la ecuacion diferencial
  74. END FUNCTION
  75.  
  76.  
  77.  
  78. !---------------------------------------------SUBRUTINA ERROR GLOBAL----------------------------------------------------------
  79. SUBROUTINE Error_Global(aprox_1,Inc)
  80. USE Data_Euler
  81. IMPLICIT NONE
  82. REAL(8) t_i, exact_sol, Error_Glob,Inc
  83. REAL(8),DIMENSION(2*dim)::aprox_1
  84. INTEGER i
  85. Error_Glob=0.d0
  86.  
  87.     t_i=t_min
  88.     OPEN(4,file="Error_Global_k=0.1")
  89.     PRINT*, "Error_Gobal_k=0.001"
  90.     PRINT*, "         Iter  t_i                     Error_Glob"
  91.     DO i=1,2*dim,1
  92.         Error_Glob=abs(aprox_1(i)-exact_sol(t_i))
  93.             WRITE(4,*) t_i,Error_Glob
  94.             Print*, i,t_i, Error_Glob
  95.         t_i=t_i+Inc
  96.     END DO
  97.     PRINT*, "-------------------------------------------------------------------------------------------------"
  98. END SUBROUTINE
  99.  
  100.  
  101.  
  102. REAL(8) FUNCTION exact_sol(t_i)
  103. Implicit none
  104. REAL(8) t_i, A, denom
  105.  
  106. denom= 1.d0 + 4.d0 * dacos(-1.d0)**2.d0
  107.  
  108. A= 1.d0 + (2.d0 *  dacos(-1.d0))/ Denom
  109.  
  110. exact_sol= (1.d0/denom)* (sin(2.d0*dacos(-1.d0)*t_i) - (2.d0*dacos(-1.d0)*cos(2.d0*dacos(-1.d0)*t_i))) + A* exp(-t_i)
  111.  
  112. END FUNCTION
  113.  
  114.  
  115. !------------------------------------------SUBRUTINA COCIENTE DE PRECISION CON SOLUCION EXACTA--------------------------------------------
  116. SUBROUTINE Cociente_con_exacta(aprox_1,aprox_2)
  117. USE Data_Euler
  118. IMPLICIT NONE
  119. REAL(8) Q,t_i,exact_sol
  120. REAL(8),DIMENSION(dim)::aprox_1
  121. REAL(8),DIMENSION(2*dim)::aprox_2
  122. INTEGER i
  123. t_i=t_min
  124.     OPEN(10,FILE="cociente_con_exacta")
  125.     DO i=1,dim,1
  126.         Q=(aprox_1(i)-exact_sol(t_i))/(aprox_2(2*i-1)-exact_sol(t_i))
  127.         WRITE(10,*) t_i,Q
  128.         t_i=t_i+k
  129.     END DO
  130. END SUBROUTINE
  131.  
  132.  
  133. !-----------------------------------------SUBRUTINA COCIENTE DE PRECISION SIN SOLUCION EXACTA---------------------------------------------
  134. SUBROUTINE Cociente_sin_exacta(aprox_1,aprox_2,aprox_3)
  135. USE Data_Euler
  136. IMPLICIT NONE
  137. REAL(8) Q,t_i
  138. REAL(8),DIMENSION(dim)::aprox_1
  139. REAL(8),DIMENSION(2*dim)::aprox_2
  140. REAL(8),DIMENSION(4*dim)::aprox_3
  141. INTEGER i
  142. t_i=t_min
  143.     OPEN(11,FILE="cociente_sin_exacta")
  144.     DO i=1,dim,1
  145.         Q=(aprox_1(i)-aprox_2(2*i-1))/(aprox_2(2*i-1)-aprox_3(4*i-3))
  146.         WRITE(11,*) t_i,Q
  147.         t_i=t_i+k
  148.     END DO
  149. END SUBROUTINE
  150.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement