Hello, I’m trying to program a subroutine that solves differential equations using the Runge-Kutta 4 method. To try if it’s correct I’m implementing it on a pendulum equation so I can plot it and check if the result is correct. Although i though it was a very simple formula, I am having some struggles because when excecuting I have the following message : Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
This messages somewtimes occur and I tried to search for the memory error but can seem to find it on the code. Can someone give it a go?
Thanks!
PROGRAM PREPA8
IMPLICIT NONE
DOUBLE PRECISION:: V, E, dx, E1, E2, E3, error, pi, grav, longitud
INTEGER:: N, i, iter, nequ
DOUBLE PRECISION:: yin_0(2), yy1(2)
EXTERNAL:: EDO, pendolSimple
COMMON/DADES/V
!Dades ctts::
V=-2.4d0
pi=4d0*atan(1d0)
grav = 3.71d0 !m/s^2
longitud = 0.45d0 !m
n=1300 !número de passos
!Inicialitzem els valors amb les condicions inicials
yin_0(1) = 0.02d0
yin_0(2) = 0d0
dx=0.0003d0
do i = 1, N
call RungeKutta4order(nequ, dx, yin_0,yy1, pendolSimple)
write(*,*) dx*i, yy1
!canviem les variables pel bucle
yin_0=yy1
enddo
END PROGRAM PREPA8
IMPLICIT NONE
INTEGER:: nequ, i
DOUBLE PRECISION:: yyin(nequ), yyout(nequ), k1(nequ), k2(nequ), k3(nequ), k4(nequ), yaux(nequ)
DOUBLE PRECISION:: x, dx
x=0d0 !realment no necessitem x
call func(nequ, x, yyin, k1) !k1 = f(x0, y0)
yaux=yyin+(dx+k1/2d0)
call func(nequ, x+(dx/2d0), yaux, k2)
yaux=yyin +(dx*k2/2d0)
call func(nequ, x+(dx/2d0), yaux, k3)
yaux=yyin+(dx*k3)
call func(nequ, x+dx, yaux, k4)
yyout=yyin+(dx/6d0)*(k1+k2*2d0+2d0*k3+k4)
END SUBROUTINE RungeKutta4order
SUBROUTINE pendolSimple(yin, f)
IMPLICIT NONE
DOUBLE PRECISION:: yin(2), f(2), grav, longitud, massa
grav = 3.71d0 !m/s^2
longitud = 0.45d0 !m
f(1) = yin(2)
f(2) = -(grav/longitud) * sin(yin(1))
return
END SUBROUTINE pendolSimple ````