Solve Ordinary differential equations systems using Runge-Kutta
- Codes made in Fortran 90
- gfortran Compiler
- Plot solution using Matlab/Octave
The code runs in Fortran 90, you will need a fortran compiler, such as gfortran. The problem conditions are changed in code, then you'll need to compile every change:
gfortran ode_solver_main.f90 -o <your_exe_name>
Then, run:
- On Windows
your_exe_name.exe
- On Linux
./your_exe_name.out
After this, the code will generate three .out files.
- mash_info.out : Contain the points of domain discretization.
- output_solution.out : Contain the solution for each point
You will need Matlab or Octave to run the .m code. Once with Matlab/Octave opened, just run the code with execute button and watch the solution change in time.
We solve a Diferential Equation System using 4 order Runge-Kutta method
To set the interval that solution will be calculated
intr_x = 0.400
The number of points that the solution will be calculated
nodes_number = 1000
To set the system, follow the steps:
- First, you'll need set the system size
Example:
!============================ System Size ============================!
system_size = 3
- Set the initial system condition
Example:
!======================== Initial conditions ==========================!
old_sol(1) = 5.000
old_sol(2) = 1.000
old_sol(3) = -3.1415
- Setting the functions
Example:
function f(x, u) result( f_res )
real(8), intent(in) :: x
real(8), intent(in), dimension(:) :: u
real(8), dimension( size(u) ) :: f_res
!===== function =====!
f_res(1) = 3*x - u(1)
f_res(2) = u(2) + 3*u(1) - u(3)
f_res(3) = log(x) - u(3) + (u(2))**2
end function f