% Initial velocity
v0 = [200.0, 100.0];

% Initial particle position
p0 = [0.0, 0.0];

% Acceleration of particle
a = [0, -9.81];

% Size of timestep
dt = 0.5;

% Start time
t = 0;

% Analytical ("true") solution
analytic = @(t) 0.5.*a.*t.*t + t.*v0 + p0;

% Plotting help
figure('units','normalized','outerposition',[0 0 1 1])
simulated_graph = animatedline(p0(1), p0(2), 'Color', 'r');
analytic_graph = animatedline(p0(1), p0(2), 'Color', 'b', 'LineStyle', '--');
axis([0, 4200, 0, 550]);
legend('Simulated', 'Analytic');
title('Parabolic motion Euler');

% Loop over time until we hit ground
while p0(2) >= 0.0
    % Increase time
    t = t + dt;
    
    % Update velocity and position
    v1 = v0 + dt.*a;
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Dette er linjen du må endre på %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    p1 = p0 - [0.1, 0.1];
    
    % Compute analytic ("true") solution
    p1_analytic = analytic(t);
   
    % Plot
    addpoints(simulated_graph, p1(1), p1(2));
    addpoints(analytic_graph, p1_analytic(1), p1_analytic(2));
    drawnow;
    pause(0.1);
    
    % Update our new starting position
    v0 = v1;
    p0 = p1;
end



