% Metodo de Euler integrado num intervalo (ti,tf) com 
% condicao inicial (t0,x0) e passo h

function x = Euler_twosided(ti,t0,tf,h,x0,F)

% integracao no futuro

    tp = (t0:h:tf)';

    xp = zeros(length(tp),length(x0));
    xp(1,:) = x0;
    
    for i = 2:length(tp)
        
        xp(i,:) = xp(i-1,:) + h.*F(tp(i-1),xp(i-1,:));
        
    end

% integracao no passado

    tm = (ti:h:t0)';

    xm = zeros(length(tm),length(x0));
    xm(length(tm),:) = x0;
    
    for i = 1:length(tm)-1
 
        j = length(tm)-i;
        xm(j,:) = xm(j+1,:) - h.*F(tm(j+1),xm(j+1,:));
        
    end

% concatenacao

    x=[xm(1:length(tm)-1);xp];

end