Euler Method in Fortran - HELP

In summary, the conversation is about using Euler method in Fortran to calculate an equation with a given deltat and number of iterations. The problem mentioned is that the program is not assuming the correct values for Yn in each step, and the suggestion is to put the Euler loop inside a time step loop.
  • #1
sayellow
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
 
Technology news on Phys.org
  • #2


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?
 
  • #3
Program Exercise1

I would suggest checking your code for any potential errors or mistakes. It seems like your program is not correctly updating the values of Yn and Yn1, which could be causing the issue you mentioned. You may also want to double check the initial conditions and make sure they are set correctly. Additionally, you can try debugging your code step by step to see where the error is occurring. If you are still having trouble, reaching out to a colleague or professor for assistance could also be helpful. Good luck!
 

1. What is the Euler Method in Fortran?

The Euler Method is a numerical method used in computer programming to approximate solutions to differential equations. In Fortran, it involves dividing the interval of interest into smaller subintervals and using a linear approximation to estimate the solution at each point.

2. How does the Euler Method work in Fortran?

In Fortran, the Euler Method works by taking the initial value of a differential equation and using it to calculate the next value at each subsequent point. This is done by using the derivative of the function at each point and multiplying it by the step size, and then adding it to the previous value.

3. What are the advantages of using the Euler Method in Fortran?

The Euler Method in Fortran is relatively easy to implement and is useful for solving simple differential equations. It also allows for the prediction of future values based on the current values, making it a useful tool for modeling systems.

4. What are some potential limitations of the Euler Method in Fortran?

One limitation of the Euler Method in Fortran is that it only provides an approximation of the solution and may not be accurate for more complex differential equations. It also has a tendency to accumulate errors over time, especially if the step size is too large.

5. How can I improve the accuracy of the Euler Method in Fortran?

To improve the accuracy of the Euler Method in Fortran, you can decrease the step size, which will result in more calculations but a more accurate solution. Additionally, using a more advanced numerical method, such as the Runge-Kutta method, may also improve accuracy.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
Replies
7
Views
2K
  • Programming and Computer Science
Replies
4
Views
3K
  • Calculus and Beyond Homework Help
Replies
12
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
11
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
20
Views
1K
Back
Top