Hi everybody,(adsbygoogle = window.adsbygoogle || []).push({});

I am programming a new code for a problem.

The problem is numerically solving the Simple Harmonic Motion using the Euler method. This approach is just an approximate solution and not a exact solution, however when I run the code successfully and plot my data, it comes up as an exact solution and the plot is exactly the same as sinusoidal harmonic motion. (while I am expecting to detect error!)

I'm really not sure where I am going wrong here. Any help would be appreciated. Thank you!

Here is my code:

program SHM_Euler

implicit none

real, dimension(100) :: x, v, t

real, dimension(100) :: a

integer :: i

real :: dt !(Step Size)

x(1) = 0.01745

t(1) = 0.00

dt = 0.1

v(1)=0

write (*,*) ' t x(t) v(t) '

do i=1, 100

t(i+1) = t(i) + dt

v(i) = -0.0546*sin(3.1305*t(i)) !Velocity

a(i)=-0.1710*cos(3.1305*t(i)) !Acceleration

x(i+1) = x(i) + v(i)*dt

v(i+1) = v(i) + a(i)*dt

write(6,'(3(e12.5,3x))') t(i+1), x(i+1), v(i+1)

t(i) = t(i+1)

x(i) = x(i+1)

v(i)=v(i+1)

end do

end program SHM_Euler

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Euler method in Fortran

Loading...

Similar Threads - Euler method Fortran | Date |
---|---|

Fortran program for oscillator using Euler method | Oct 22, 2013 |

Fortran 90. Euler and Runge-Kutta's method | Jun 22, 2011 |

Euler's Method in Python | Feb 12, 2011 |

Euler Method in Fortran - HELP | Oct 30, 2008 |

Fortran 90, Euler's method help | May 4, 2008 |

**Physics Forums - The Fusion of Science and Community**