This type of equations involves the function of the independent variable and its derivatives. Example of ODE can be dy/dx = x + y. Prerequisites knowledge of ordinary differential equation and how to find their exact solutions using methods like calculating particular integral and integration factor etc.
The whole idea is concentrated on tangent to problem curve. 
In this tutorial we focus on:  Euler's Method
 Modified Euler's Method
 RungaKutta Method( of 4th Code)
This method is one of the most widely used method and again it is also an iterative method which includes the routine of well known Euler's Method. Suppose dy/dx = f(x,y) , y = y _{0} when x = x _{0} to find y for x = x _{1} = x _{0} + h we have to compute k _{1} = hf(x _{0}, y _{0}) k _{2} = hf(x _{0} + h/2, y _{0} + k _{1}/2) k _{3} = hf(x _{0} + h/2, y _{0} + k _{2}/2) k _{4 }= hf(x _{0} + h/2, y _{0} + k _{3}) k = 1/6( k _{1} + 2k _{2} + 2k _{3} + k _{4}), Now the value of y _{1} of y for x _{1} = x _{0} +k is given by y _{1} = y _{0} + k similarly we have to repeat for next value of x , x_{2} ,x_{3 }... and so on
In General for x _{n} k _{1 }= hf(x _{n1}, y _{n1}) k _{2} = hf(x _{n1} + h/2, y _{n1} + k _{1}/2) k _{3} = hf(x _{n1} + h/2, y _{n1} + k _{2}/2) k _{4} = hf(x _{n1} + h/2, y _{n1} + k _{3}) k = 1/6( k _{1} + 2k _{2} + 2k _{3 }+ k _{4}), y _{n} = y _{n1} + k  Programming implementation of RK4 in C++
#include<iostream>
using namespace std;
double f(double x,double y){
return x*y + 1;
}
double f1(double x, double y){
return 3*x + y/2;
}
int main(){
//Suppose dy/dx = f(x,y) and y = y0 when x=x0
double x0,y0;
double xn,yn;
double k1,k2,k3,k4, k;
cout<<"Provide initial (x0,y0) whose differential equ is defined:";
cin>>x0>>y0;
cout<<"Enter the value of x for which you need to find out the y=?:";
cin>>xn;
double h = (xnx0)/5;
yn = y0;
for(double xi = x0 ; xi < xn ; xi += h){
k1 = h*f(xi , yn);
k2 = h*f(xi + h/2, yn + k1/2);
k3 = h*f(xi + h/2, yn + k2/2);
k4 = h*f(xi + h/2, yn + k3);
k = (k1 + 2*k2 + 2*k3 + k4)/6;
yn = yn+k;
}
printf("Value of y at x=%f is %0.4f when h: %f\n",xn , yn, h);
return 0;
}
 Code Execution of RK4 for dy/dx = xy +1 , y(0)=1 at x = 0.1
Provide initial (x0,y0) whose differential equ is defined:0 1
Enter the value of x for which you need to find out the y=?:0.1
Value of y at x=0.100000 is 1.1052 when h: 0.020000
Note: check the value of h, calculate the accuracy of the method and compare with other methods of finding the solution of the ODE. 
DescriptionModified Euler's Method is just the extended version of Euler's Method to increase the accuracy of the approximate solution. It's recommended for you to go through Euler's Method. The approximate value of y_{1} of y for x = x_{1} = x_{0} +h by Euler's method is given by
y_{1} = y_{0 }+ hf(x_{0}, y_{0})
so in edition to attend more accuracy we repeat the below formula,
y_{1}^{(1)} = y_{0} + h/2[ f(x_{0}, y_{0}) + f(x_{1}, y_{1}) ]
y_{1}^{(2) }= y_{0} + h/2[ f(x_{0}, y_{0}) + f(x_{1}, y_{1}^{(1)})] ...
in pan and paper process continues untill two value coincides now we have value of y_{1}
y _{2} = y _{1} + hf(x _{1}, y _{1}) repeat the above process for y2 y _{2}^{(1)} = y _{1} + h/2[ f(x _{1}, y _{1}) + f(x _{2}, y _{2}) ] y_{2}^{(2) }= y_{1} + h/2[ f(x_{1}, y_{1}) + f(x_{2}, y_{2}^{(1)})] ...  Programming implementation of modified Euler's Method in C++
#include<iostream>
#include<math.h>
using namespace std;
double f(double x,double y){
return x+y; // dy/dx = x + y
}
double f1(double x,double y){
return log2(x+y);
}
int main(){
// COde for solving Ordinary differential equations
// dy/dx = f(x,y)
//Define your equation
//Given y(x0) = y0
//Need to find y(xn) = yn
double x0,y0;
double xn,yn;
cout<<"Provide initial (x0,y0) whose differential equ is defined:";
cin>>x0>>y0;
cout<<"Enter the value of x for which you need to find out the y=?:";
cin>>xn;
double h = (xnx0)/5;
yn = y0;
for(double xi = x0;xi < xn; xi += h){
cout<<xi<<" "<<yn<<endl;
double YnPrevious = yn;
yn = yn + h*f(xi , yn);
for(int i=0;i<5;i++){
yn = YnPrevious + h*( f(xi,YnPrevious) + f(xi+h,yn))/2;
}
// Yn = Yn1 + h*f(Xn1,Yn1)
}
printf("Value of y at x=%f is %0.4f when h: %f\n",xn , yn, h);
return 0;
}
 Code Execution for dy/dx = x + y ,y(0) =1 ,for x=0.3
Provide initial (x0,y0) whose differential equ is defined:0 1
Enter the value of x for which you need to find out the y=?:0.3
0 1
0.06 1.06371
0.12 1.13507
0.18 1.21456
0.24 1.30268
Value of y at x=0.300000 is 1.4000 when h: 0.060000
Note: In code, h is defined constant depending upon interval size, but you can change as h cause accuracy difference, try out the code for other functions.

DescriptionConsider a defferential equation dy/dx = f(x,y) with initial condition y = y _{0} when x = x _{0}, suppose we want to find y for x = x _{n}. First we divide the interval [x _{0},x _{n}] into n equal parts. x _{0}, x _{1} = x _{0} +h , x _{2} = x _{0} + 2h, .. , x _{n} where h is small. Using the equation of tangent at point (x _{0}, y _{0}) y  y_{0} = dy/dx * (x  x_{0}) where dy/dx = f(x_{0},y_{0})
In the small interval [x_{0}, x_{1}] or [x_{0}, x_{0}+h] we approximate the solution curve by the tangent, So the approximate value of y_{1} at point y_{1} can be given by
y_{1}  y_{0} = f(x_{0}, y_{0})( x_{0} + h  x_{0})
y_{1} = y_{0} + hf(x_{0}, y_{0})
Similarly
y_{2} = y_{1 }+ hf(x_{1}, y_{1}) ...
y _{n}_{ }= y _{n}_{1} + hf(x _{n}_{1}, y _{n}_{1}) In the Euler's method we approximate the solution curve by tangent in each subinterval by a sequence of short lines and therefore unless h is very small the error is bound to be quite significant.
 Programming implementation of Euler's Method in C++
#include<iostream>
#include<math.h>
using namespace std;
double f(double x,double y){
return x+y; // dy/dx = x + y
}
double f1(double x,double y){
return log2(x+y);
}
int main(){
// COde for solving Ordinary differential equations
// dy/dx = f(x,y)
//Define your equation
//Given y(x0) = y0
//Need to find y(xn) = yn
double x0,y0;
double xn,yn;
cout<<"Provide initial (x0,y0) whose differential equ is defined:";
cin>>x0>>y0;
cout<<"Enter the value of x for which you need to find out the y=?:";
cin>>xn;
double h = (xnx0)/5;
yn = y0;
for(double xi = x0;xi < xn; xi += h){
cout<<yn<<endl;
yn = yn + h*f(xi , yn);
// Yn = Yn1 + h*f(Xn1,Yn1)
}
printf("Value of y at x=%f is %0.4f when h: %f\n",xn , yn, h);
return 0;
}
 Code execution for dy/dx = x + y ,y(0) = 1 ,finding y for x = 0.1
Provide initial (x0,y0) whose differential equ is defined:0 1
Enter the value of x for which you need to find out the y=?:0.1
1
1.02
1.0408
1.06242
1.08486
Value of y at x=0.100000 is 1.1082 when h: 0.020000
Note: In code their h is defined constant, change it if needed as accuracy completely dependent on the value of h.

