FORTRAN: second-order ODE with Euler Method

In summary: What is wrong with the following code?FOR i=1:10y(i) = y(1) + v(i-1)*dtv(i) = v(i-1) + dt*f(y(i-1), v(i-1))t(i) = t(i-1) + dtThe code does not use the correct variable to hold the result of the function. You should use v_0 instead of v in the for loop.
  • #1
Cecily
2
0

Homework Statement


Dear all, please help. I have tried this question and came up with strange numbers, my fortran is definitely not correct. Please help!

When the effect of the air resistance is taken into account, the equation of motion for a particle of mass
m falling vertically in a gravitational field is given by
m*y''= -m*g - b*v (*)
where g is the gravitational acceleration and v = dy/dt is the velocity. The coefficient b specifies the strength of the interaction between the air and the particle. The initial conditions are y(0) = 1000 m and v(0) = 0 ms-2. Take m = 1 kg and g = 9.8 ms-2 in the following.Write a Fortran program that uses the Euler method to solve the initial value problem.
Consider the case without air resistance b = 0. Plot y(t) against t until y = 0 (i.e., the particle has
reached the ground) for two different time steps Δt = 1 s and 0.01 s in one figure. Plot also the
exact solution in the same figure for comparison.

Homework Equations


The Attempt at a Solution

 
Last edited:
Physics news on Phys.org
  • #2
here is my definitely wrong program...

PROGRAM lab5a
IMPLICIT NONE

INTEGER :: i
REAL :: dt, y_0, v_0, f
REAL, DIMENSION(200) :: y, v, t
REAL, PARAMETER :: epsilon = 1D-6

y(1) = y_0
v(1) = v_0

dt = 1.D0
DO i=2
y(i) = y(1) + v(i-1)*dt
v(i) = v(i-1) + dt*f(y(i-1), v(i-1))
t(i) = t(i-1) + dt

WRITE (10, *) t(i), y(i)

IF (y(i) < epsilon) exit

END DO

dt = 1D-2

DO i=1
y(i) = y(1) + v(i-1)*dt
v(i) = v(i-1) + dt*f(y(i-1), v(i-1))
t(i) = t(i-1) + dt

WRITE (11, *) t(i), y(i)

IF (y(i) < epsilon) exit

END DO

END PROGRAM lab5a

!============================
REAL FUNCTION f(y, v)
IMPLICIT NONE
REAL :: y, v
REAL :: m=1, g=9.8, b=0

f = -g - b / m * v

END FUNCTION
 
Last edited:
  • #3
Cecily said:
here is my definitely wrong program...

PROGRAM lab5a
IMPLICIT NONE

INTEGER :: i
REAL :: dt, y_0, v_0, f
REAL, DIMENSION(200) :: y, v, t
REAL, PARAMETER :: epsilon = 1D-6

y(1) = y_0
v(1) = v_0

dt = 1.D0
DO i=2
y(i) = y(1) + v(i-1)*dt
v(i) = v(i-1) + dt*f(y(i-1), v(i-1))
t(i) = t(i-1) + dt

WRITE (10, *) t(i), y(i)

IF (y(i) < epsilon) exit

END DO

dt = 1D-2

DO i=1
y(i) = y(1) + v(i-1)*dt
v(i) = v(i-1) + dt*f(y(i-1), v(i-1))
t(i) = t(i-1) + dt

WRITE (11, *) t(i), y(i)

IF (y(i) < epsilon) exit

END DO

END PROGRAM lab5a

!============================
REAL FUNCTION f(y, v)
IMPLICIT NONE
REAL :: y, v
REAL :: m=1, g=9.8, b=0

f = -g - b / m * v

END FUNCTION

Your DO loops are not right. For the first one, you have
DO i=1
.
.
.
END DO

You need to indicate the final value of your loop control variable, like this:
DO i=1 , 10
.
.
.
END DO

Your other DO loop has the same problem.
 

Related to FORTRAN: second-order ODE with Euler Method

1. What is FORTRAN?

FORTRAN (Formula Translation) is a high-level programming language commonly used in scientific and engineering applications. It was created in the 1950s for numerical computing and is known for its efficient execution of mathematical operations.

2. What is a second-order ODE?

A second-order ODE (Ordinary Differential Equation) is a mathematical equation that involves a function and its derivatives. It represents the relationship between a variable and its rate of change. In FORTRAN, second-order ODEs are commonly used to model physical systems and phenomena.

3. How does the Euler Method work for solving second-order ODEs in FORTRAN?

The Euler Method is a numerical method used to approximate the solutions of differential equations. In FORTRAN, it involves breaking down the second-order ODE into a system of two first-order ODEs, which can then be solved using the Euler Method. This method uses small time steps to approximate the solution and is less accurate than other methods, but it is simple to implement.

4. What are the advantages of using FORTRAN for solving second-order ODEs?

FORTRAN is a powerful language specifically designed for scientific and engineering applications. It has built-in functions and libraries for mathematical operations, making it efficient for solving complex equations. Additionally, FORTRAN has a long history and is well-established in the scientific community, with many resources and support available.

5. Are there any limitations to using FORTRAN for second-order ODEs?

While FORTRAN is a popular choice for scientific computing, it does have some limitations for solving second-order ODEs. One limitation is that it does not support complex numbers, which may be needed for certain equations. Additionally, FORTRAN is not as user-friendly as other programming languages, so it may have a steeper learning curve for those who are not familiar with it.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
18
Views
2K
Back
Top