% 6.581 PS4
% Problem 1
% integrate.m

function [t, x] =  integrate(func, time, ic)

% Simulates the system defined by func and returns the trajectory.
%
% func : a function that takes x as an argument and returns the time
%        derivative of x and the jacobian of x. For example:
%            function [dxdt, dxdx] = myfun(x)
%               dxdt = -x^2;
%               dxdx = -2*x;
% time : the time for the simulation.  If time is length 2 then time(1) is
%        the start time and time(2) is the end time.  If time is longer
%        than 2 then the the trajector will be samples at the times in time. 
%
% ic   : the inital conditions for the system.
%
% Returns:
%
% t    : the time points of the trajectory
% x    : the values of the system variables at each time point
%

opts   = odeset('Jacobian', @helper2);
[t, x] = ode23s(@helper, time, ic, opts,func);


function dxdt = helper(t, x, fun)
    [dxdt, dxdx] =  fun(x);

function dxdx = helper2(t, x, fun)
    [dxdt, dxdx] =  fun(x);
