% metodo de Euler aprimorado (explicito)
function [t,x] = EulerAP(t0,tf,x0,dxdt,n)

% atribui o valor de n = 100 como padrao
if nargin < 5, n = 10; end

% armazenado as condicoes iniciais
t(1) = t0;
xs   = x0;
x    = x0;

% calculo do passo
h = (tf-t0)/n;

% loop de integracao
for i = 1:n
     dx = feval(dxdt,t(i),xs);
     xs = xs+.5*h*dx;
     dx = feval(dxdt,t(i)+.5*h,xs);
     xs = xs+h*dx;
     t(i+1) = t(i)+h;
     x = vertcat(x,xs);
endfor

end