Euler Method in Fortran - HELP

  • Fortran
  • Thread starter sayellow
  • Start date
  • #1
1
0
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
Please, can someone help me?

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
 

Answers and Replies

  • #2
Integral
Staff Emeritus
Science Advisor
Gold Member
7,201
56


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?
 

Related Threads on Euler Method in Fortran - HELP

Replies
2
Views
12K
  • Last Post
Replies
5
Views
7K
Replies
3
Views
2K
Replies
15
Views
31K
  • Last Post
Replies
13
Views
18K
Replies
17
Views
19K
  • Last Post
Replies
1
Views
11K
  • Last Post
Replies
4
Views
3K
Replies
9
Views
2K
Top