Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- !Este Programa fue realizado por Lillieskold, Thomas Enrique
- !Instituto Universitario Aeronautico - 2023
- !Docentes: Giovacchini, Juan Pablo; Sacco, Carlos
- !Asignatura: Calculo Numerico
- !-------------------------------------------------------------------------------
- !----------------DECLARACION DE VARIABLES PARA Euler-----------------------------
- MODULE Data_Euler
- REAL(8),PARAMETER::t_min=0.d0
- REAL(8),PARAMETER:: t_max=2.d0
- REAL(8),PARAMETER:: V_0=1.d0
- REAL(8),PARAMETER:: k=0.1
- INTEGER,PARAMETER:: dim=(t_max-t_min)/k
- END MODULE Data_Euler
- !--------------------------------------INICIO DEL MAIN PROGRAM-----------------------------------------------------------------------------
- Program Euler_Forward
- USE Data_Euler
- Implicit none
- REAL(8),DIMENSION(dim)::aprox_1
- REAL(8),DIMENSION(2*dim)::aprox_2
- REAL(8),DIMENSION(4*dim)::aprox_3
- !CALL Euler(aprox_1,k,dim)
- CALL Euler(aprox_2,k/2.d0,2*dim)
- !CALL Euler(aprox_3,k/4.d0,4*dim)
- CALL Error_Global(aprox_2,k/2.d0)
- !CALL Cociente_con_exacta(aprox_1,aprox_2)
- !CALL Cociente_sin_exacta(aprox_1,aprox_2,aprox_3)
- END PROGRAM
- !---------------------------------------FINAL DEL MAIN PROGRAM------------------------------------------------------------------------------
- !---------------------------------------SUBRUTINA EULER-------------------------------------------------------------------------------------
- SUBROUTINE Euler(aprox,Inc,ext)
- USE Data_Euler
- Implicit none
- REAL(8) v_n,v_o,func,t_i,Inc
- INTEGER ext
- REAL(8),DIMENSION(ext)::aprox
- Integer Iter,i
- v_o=v_0
- t_i=t_min
- iter=0
- OPEN(3,FILE="Write_outs_k=0.1")
- PRINT*, " Iter T_i v_n"
- DO i=1,ext,1
- iter=iter+1
- aprox(i)=v_o
- v_n = v_o + Inc * func(v_o,t_i)
- Write(3,*) t_i,aprox(i)
- PRINT*, Iter,t_i,aprox(i)
- v_o=v_n
- t_i=t_i+Inc
- END DO
- PRINT*, "------------------------------------------------------------------------------------------------------"
- END SUBROUTINE
- REAL(8) FUNCTION func(y,x)
- Implicit none
- REAL(8) y,x
- func=-1.d0*y+ sin(2.d0*dacos(-1.d0)*x) !Esta funcion es la que acompaña a la ecuacion diferencial
- END FUNCTION
- !---------------------------------------------SUBRUTINA ERROR GLOBAL----------------------------------------------------------
- SUBROUTINE Error_Global(aprox_1,Inc)
- USE Data_Euler
- IMPLICIT NONE
- REAL(8) t_i, exact_sol, Error_Glob,Inc
- REAL(8),DIMENSION(2*dim)::aprox_1
- INTEGER i
- Error_Glob=0.d0
- t_i=t_min
- OPEN(4,file="Error_Global_k=0.1")
- PRINT*, "Error_Gobal_k=0.001"
- PRINT*, " Iter t_i Error_Glob"
- DO i=1,2*dim,1
- Error_Glob=abs(aprox_1(i)-exact_sol(t_i))
- WRITE(4,*) t_i,Error_Glob
- Print*, i,t_i, Error_Glob
- t_i=t_i+Inc
- END DO
- PRINT*, "-------------------------------------------------------------------------------------------------"
- END SUBROUTINE
- REAL(8) FUNCTION exact_sol(t_i)
- Implicit none
- REAL(8) t_i, A, denom
- denom= 1.d0 + 4.d0 * dacos(-1.d0)**2.d0
- A= 1.d0 + (2.d0 * dacos(-1.d0))/ Denom
- 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)
- END FUNCTION
- !------------------------------------------SUBRUTINA COCIENTE DE PRECISION CON SOLUCION EXACTA--------------------------------------------
- SUBROUTINE Cociente_con_exacta(aprox_1,aprox_2)
- USE Data_Euler
- IMPLICIT NONE
- REAL(8) Q,t_i,exact_sol
- REAL(8),DIMENSION(dim)::aprox_1
- REAL(8),DIMENSION(2*dim)::aprox_2
- INTEGER i
- t_i=t_min
- OPEN(10,FILE="cociente_con_exacta")
- DO i=1,dim,1
- Q=(aprox_1(i)-exact_sol(t_i))/(aprox_2(2*i-1)-exact_sol(t_i))
- WRITE(10,*) t_i,Q
- t_i=t_i+k
- END DO
- END SUBROUTINE
- !-----------------------------------------SUBRUTINA COCIENTE DE PRECISION SIN SOLUCION EXACTA---------------------------------------------
- SUBROUTINE Cociente_sin_exacta(aprox_1,aprox_2,aprox_3)
- USE Data_Euler
- IMPLICIT NONE
- REAL(8) Q,t_i
- REAL(8),DIMENSION(dim)::aprox_1
- REAL(8),DIMENSION(2*dim)::aprox_2
- REAL(8),DIMENSION(4*dim)::aprox_3
- INTEGER i
- t_i=t_min
- OPEN(11,FILE="cociente_sin_exacta")
- DO i=1,dim,1
- Q=(aprox_1(i)-aprox_2(2*i-1))/(aprox_2(2*i-1)-aprox_3(4*i-3))
- WRITE(11,*) t_i,Q
- t_i=t_i+k
- END DO
- END SUBROUTINE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement