% ====================================================================================
% =====   Discritized Approximation of The Exact Solution of: dy/dx = exp(x)     =====
% ===== The Exact Solution of The Ordinary Differential Equation is: y(x)=exp(x) =====
% =====               << The 2nd Order Adams - Bashforth Method >>               =====
% ====================================================================================

clc
clear

dt=0.1;			%The Time Step
Time=0:dt:4;	%The Time Interval

AdamsBashforthApproximation(1)=1;	%The Initial Condition
AdamsBashforthApproximation(2)=1;	%The Initial Condition

for i=2:length(Time)-1
   Function1=exp(Time(i));
   Function2=exp(Time(i-1));
   AdamsBashforthApproximation(i+1)=AdamsBashforthApproximation(i)+((dt/2)*(3*Function1-Function2));
end

%The Exact Solution
ExactSolution=exp(Time);

figure(1);
plot(Time,ExactSolution,'b',Time,AdamsBashforthApproximation,'r');
legend('Exact Solution','2nd Order Adams - Bashforth Approximation');
title('2nd Order Adams - Bashforth Approximation, dt = 0.1');
xlabel('Time');
ylabel('Y');
grid on