% IVP y'= -2*y+1, y(0)=1, exact solution y(t)=0.5*exp(t)+0.5

% step size
h = 0.01

% prepare the array
nn = 10/h

% initial values
y = 0*(1:nn);     % array of nn zeros
y(1) = 1;        % y0
y(2) = 0.5*exp(-2*h)+0.5;   % y1

for( n=2:(nn-1))
     y(n+1) = y(n-1) + 2*h*(-2*y(n) +1);
end

plot(y)
