% ----------------------------
% euler.m
% Euler method 
% ----------------------------
clear all;close all;
exact = @(x) -exp(-x)-x.^4/2 + 1;
fp = @(x) exp(-x)-2.*x.^3;
h = 0.01;
x = 0:h:1;
N=size(x,2);
y = 0.*x;
for i = 2:N
   y(i) = y(i-1) + fp(x(i-1))*h; 
end
plot(x,y,'bo',x,exact(x),'g-');
legend('Euler','exact');