% the program takes the initial data y_0 at the initial time x_0 and 
% computes up to time x_final using timesteps of size dx.  It creates
% two vectors, x and y, which you can then plot against each other
% plot(x,y)
%
% [x,y] = taylor_2(y_0,x_0,x_final,dx)

function [x,y] = taylor_2(y_0,x_0,x_final,dx)

% for dy/dx = f(y(x),x)
% y(x+dx) ~ y(x) + dx y'(x) + dx^2/2 y''(x)
%         = y(x) + dx f(y(x),x) + dx^2/2 ( f_y(y(x),x)f(y(x),x) + f_x(y(x),x)
%
% number of steps to take 
n = ceil((x_final-x_0)/dx) + 1;

% put initial data into vector
x(1) = x_0;
y(1) = y_0;
for i=1:n-1
  y(i+1) = y(i) + dx*F(y(i),x(i));
  y(i+1) = y(i+1) + F1(y(i),x(i))*dx^2/2;
  x(i+1) = x_0 + i*dx;
end