%Differential Equation: dy/dx=y-(1/2)*exp(x/2).*sin(5*x)+5*exp(x/2).*cos(5*x); y(0)=0;
f=@(x,y) y-(1/2)*exp(x/2).*sin(5*x)+5*exp(x/2).*cos(5*x);
f1=@(x,y) exp(x/2).*sin(5*x);   %Analytic Solution
xinit=0; yinit=0;       %y(xinit)=yinit {y(0)=0}

xmax=10;
x=xinit:0.1:xmax;
h=x(2)-x(1);
m=length(x);
y=zeros(1,m);
y(1)=yinit;

for n=1:m-1
    y(n+1)=y(n)+h*f(x(n),y(n));
    y(n+1)=y(n)+h*(f(x(n),y(n))+f(x(n+1),y(n+1)))/2;
end;
yy=exp(x/2).*sin(5*x);      %Analytic Solution

hold on;
plot(x,y,'bo-','LineWidth',1.5);
plot(x,yy,'r-','LineWidth',2.5);
title('Euler Modified Method','fontsize',14,'fontweight','bold');
legend('Euler Modified Method','Analytic','Location','NorthWest');
grid on;
hold off;