# Euler Method in Fortran - HELP

• Fortran
Euler Method in Fortran - HELP!!

Using Euler method I want to calculate the equation below, deltat=0.3, 10 times.

Problem: When n=1, Yn1(1) is calculated right. But, in the following steps it should assume that Yn(2)=Yn1(1) and the program is assuming Yn(2)=0, as well as Yn(3)=0,...and so on

Program Exercise1
!
! This Program will solve the ODE bellow using Euler Method ...
!
! dy(t)
! ______ = 2y(t) + t^2 + t
! dt
!
! Declaration of Variables
!
Implicit none
!
!
Real:: deltat1

Integer:: ts1,n,time
Real:: Yn1(1:11),Yn(1:11),tn(1:11)

Yn(1)=1
do n=1,ts1
deltat=0.3
ts1=10

tn(n)=(deltat*(n-1))+tn(n)

Yn1(n+1)=Yn(n)+deltat*(2*Yn(n)+(tn(n)**2)+tn(n))
Yn(n)=Yn1(n+1)
write (*,*) Yn1(n)

enddo

n=n+1

End

Integral
Staff Emeritus
Gold Member

first move the assignment statements for deltat and ts1 outside of your loop. You also have not initialize tn(0).

I am very uneasy with your incrementing your time variable in step with the Euler method iterations.

I think you should put the Euler loop inside of a time step loop. So you want to iterate a Euler loop at EACH time step.

You may want to look closely at the result of your time step calculation, is it producing what you want it to?