function eul
%Calculates Euler's Method
%Function is below under function fun(t,y)
%Variables 
%  delta:    time step
%  t0:       Initial time
%  tend:     End of time
%  y0:       y(t0)
%
%Mili Shah
%1/22/09
clf
delta = .05; %Delta T
t0 = 0;      %Initial time
tend = 3;    %End time
y0 = 1;      %y(t0)

t = [t0:delta:tend];
y = zeros(size(t));

y(1) = y0;
disp(sprintf('k:\tt_k\t\ty_k'));
disp(sprintf('0:\t%f\t%f',t(1),y(1)));

for i = 2:length(t)
    t(i) = t(i-1)+delta;
    y(i) = y(i-1)+delta*feval(@fun, t(i-1),y(i-1));
    disp(sprintf('%d:\t%f\t%f',i-1,t(i),y(i)));
end
plot(t,y,'*-')
hold on
[t,y]=ode23(@fun,[t(1) t(end)],y(1));   
plot(t,y(:,1),'r');
xlabel('t')
ylabel('y')
legend('Euler','Actual')
function f = fun(t,y)
f = t-y^2;