% HW4_4

% use this after FIRST_ORDER_DE_WITH_DIRECTION_FIELD
% to add a few points

% APMA 0410
% Fall 2012

hold on

N = 2; % number of steps

t_initial = t_min;
x_initial = x_min;

while t_initial >= t_min && x_initial >= x_min && x_initial <= x_max  
    % will create a new trajectory starting at point where mouse is clicked,
    % unless mouse is clicked in margin
    
    [t_initial x_initial] = ginput(1);    % click mouse on desired initial point
    t_current = t_initial;
    x_current = x_initial;
    
    t = zeros(1,N);
    x = zeros(1,N);

    n = 1;

    while n <= N
        t(n) = t_current;
        x(n) = x_current;
        n = n + 1;
        t_current = t_current + dt;
        x_current = x_current + dt*f(t_current,x_current);
    end


    plot(t(1:n-1),x(1:n-1),'r','linewidth',2)
end

xlabel('t')
ylabel('x')
deriv = func2str(f);
deriv_name = deriv(7:end);

% plot nullcline(s):
h = ezplot(f, [t_min t_max x_min x_max]);
set(h, 'color','g', 'linewidth', 2)
title(['x'' = ' deriv_name])

hold off
