function[sol]= fourth_order_RK_method(f,x0,y0,xn,h)
% This program estimates the solution of the first order differential
% equation of the form y'=f(x,y) at given point using RK4 Method
% Input	-> f  : function in the equation which is passed as a string.
%			  x0  : initial x value.
%			  y0  : initial y value.
%			  h	  : step-size length.
%			  xn  : end point where corresponding value of y to be estiamted.
% Output	-> The computed table for x and y values are displayed.
% clc;
% clear all;
% close all;
tic;
% *************************************************************************
% f=@(x,y) y; %right side term of the DE
% x0=0;y0=1;xn=1;h=0.1;
% *************************************************************************
x=x0:h:xn;
n=length(x);
y(1)=y0;
iteration=0;
for i=1:n-1
   k1=h*f(x(i),y(i));
   k2=h*f(x(i)+h/2,y(i)+k1/2);
   k3=h*f(x(i)+h/2,y(i)+k2/2);
   k4=h*f(x(i)+h,y(i)+k3);
   y(i+1)=y(i)+(k1+2*k2+2*k3+k4)/6;
   iteration=iteration+1;
end
sol=y;
e_time=toc;
error=norm(y-exp(x),inf);
M=[x;y]; % it stores the values of x and y.
fprintf('\n\n----------------------RK4 Mehod------------------------\n\n');
fprintf('This program was written by Mr. Harish Bhatt on 02,08/2013');
fprintf('\n\n\t\t x-values\t\t y-values\n');
fprintf('\t\t ---------\t\t ---------\n\n');
fprintf('\t\t %f \t\t%f \n',M);
fprintf('\n\n\t\tThe estimated value of y at %f is %f\n',x(end),y(end));
fprintf('\n\n\t\tThis method took %3d step to get the solution\n',iteration+1);
fprintf('\n\n\t\t The elasped time is %f\n',e_time);
fprintf('\n\n\t\t The maximum error is %f\n',error);
% % ------------------------Graphical Representation-------------------------
% %Plot of the numerical solution VS analytical solution y=e^x
% plot(x,y,'^-r',x,exp(x),'-');
% title('Numerical solution with RK4 VS Analytical Solution')
% xlabel('x-values')
% ylabel('y-values')
% legend('Numerical sol','Analytical sol')