mlouky
- 5
- 0
How can i solve y" + 2y =0 with RK4 and their program fortran
please I néed your helpe
please I néed your helpe
The discussion revolves around solving the ordinary differential equation (ODE) y'' + 2y = 0 using the Runge-Kutta 4th order (RK4) method in Fortran. Participants explore the formulation of the problem, initial conditions, and the implementation of the RK4 algorithm.
There is no consensus on the correct formulation of the problem or the initial conditions. Multiple competing views exist regarding the appropriate approach to solving the ODE using RK4.
Participants have not fully resolved the discrepancies in the problem statements and initial conditions, leading to confusion about the correct application of the RK4 method.
my ey is y"+2y weith y(x) = cos(2x)mlouky said:How can i solve y" + 2y =0 with RK4 and their program fortran
please I néed your helpe
y(x) = cos(2x) is not a solution of y'' + 2y = 0.mlouky said:my ey is y"+2y weith y(x) = cos(2x)
mlouky said:voila mon progam
Mod note: Added [ code ] and [ /code ] tags, below.
Fortran:Program second_ordr implicit none integer, parameter :: n=21 ! number of base points double precision, external :: f double precision, dimension(1:n) :: x, y, dy ! x, y, y' integer i open (unit=22,file="result.dat") ! boundary values x(1) = 0.0 y(1) = 0.0 x(n) = 1.0 y(n) = 1.0 ! assumptions for y'(1) - use dy(1) and dy(2) here only as a storage dy(1) = 1 dy(2) = 0 write(*,100) do i=1,n write (*,101) x(i), y(i), dy(i) end do 100 format(5x, 'x',11x, 'y',11x, 'dy') 101 format(3(1pe12.4)) stop end program second_ordr function f(x,y,dy) implicit none double precision f, x, y, dy f = 0.55*cos(0.55*x) end function f subroutine rk4_2d(f,x,y,dy,n) implicit none double precision f integer n double precision, dimension(1:n) :: x, y, dy integer i double precision h,k11,k12,k21,k22,k31,k32,k41,k42 do i=2,n h = x(i)-x(i-1) k11 = h*dy(i-1) k12 = h*f(x(i-1),y(i-1),dy(i-1)) k21 = h*(dy(i-1)+k12/2.0) k22 = h*f(x(i-1)+h/2.0, y(i-1)+k11/2.0, dy(i-1)+k12/2.0) k31 = h*(dy(i-1)+k22/2.0) k32 = h*f(x(i-1)+h/2.0, y(i-1)+k21/2.0, dy(i-1)+k22/2.0) k41 = h*(dy(i-1)+k32) k42 = h*f(x(i-1)+h,y(i-1)+k31,dy(i-1)+k32) y(i) = y(i-1) + (k11 + 2.0*(k21+k31) + k41)/6.0 dy(i) = dy(i-1)+ (k12 + 2.0*(k22+k32) + k42)/6.0 end do end subroutine rk4_2d
That is not what you wrote in your opening post. There you wrote that you want to solve $y'' + 2y = 0$, but you did not specify initial conditions. In your second post you wrote that you want to solve $y'' + 2y = 0$ with $y(x) = cos(2x)$ and boundary conditions $y(0)=0, y(1)=1$. As Mark noted, $y(x) = cos(2x)$ is not a solution of $y'' + 2y = 0$.mlouky said:I explain exactly what I want
I have an ordinary differential equation of order two y "(x) = -2cos (2x)
I am looking to solve numerically the RK4 method to write a program in FORTRAN
with y (0) = 1 and y '(0) = 0
thank you very much