Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- !!!PRINCIPAL
- program algebra
- use algebra_lineal
- use algebra_no_lineal
- implicit none
- real(8),allocatable:: U(:)
- integer::n,m,i
- real(8)::tiniciales(2),t,deltat,z
- tiniciales(1)=0.d0
- tiniciales(2)=2.d0
- n=10
- deltat=( tiniciales(2) - tiniciales(1)) / dble(n)
- m=1
- allocate(u(m))
- u=0.d0
- u(1)=(1.d0)/(2.d0)
- open(unit=10, file='resultadosdiez.dat')
- do i=1 ,n
- call Euler ( m, U, t, deltat, FdeU)
- write(10,*)t,U,exacta(t)
- z=dble(i)
- t=z*deltat
- enddo
- deallocate(u)
- close(10)
- n=100
- allocate(u(m))
- u=0.d0
- u(1)=(1.d0)/(2.d0)
- deltat=( tiniciales(2) - tiniciales(1)) / dble(n)
- open(unit=11, file='resultadoscien.dat')
- do i=1 ,n
- call Euler ( m, U, t, deltat, FdeU)
- write(11,*)t,U,exacta(t)
- z=dble(i)
- t=z*deltat
- enddo
- deallocate(u)
- close(11)
- end program
- !!!FUNCIONES
- function FdeU (m,U,t)
- real(8)::FdeU(1:m)
- real(8), intent(in):: U(1:m), t
- integer, intent(in)::m
- FdeU(1)=U(1) - t**2 +1
- end function
- function exacta(t)
- real(8)::exacta,t
- exacta=(t + 1.d0)**(2.d0) - ((exp (t)) / 2.d0)
- end function
- !!!EULER
- subroutine Euler ( m, U, t, dt, F)
- !*** Interface for the m--dimensional vector valued function F
- interface
- function F ( m, U, t )
- integer, intent(in) :: m
- real(8), intent(in) :: t, U(1:m)
- real(8) :: F (1:m)
- end function F
- end interface
- !*** Dummy arguments specification
- integer, intent(in) :: m
- real(8), intent(in) :: t, dt
- real(8), intent(inout) :: U(1:m)
- !*** U^{n+1} = U^n + dt * F ( U^n, t_n )
- U = U + dt * F ( m, U, t )
- end subroutine Euler
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement