% Simulation of a moving particle
close all; 
p0 = [1;0]; v0 = [0;0];
A = [2 1; 1 1]; % force matrix
% For visualization of force field
force = @(x) -(A*x);
[x,y] = meshgrid(-1.1:0.1:1.1,-1.1:0.1:1.1);
u = zeros(size(x)); v = u;
ix = 1; iy = 1;
for px = -1.1:0.1:1.1
  for py = -1.1:0.1:1.1
    f = force([px;py]);
    u(ix,iy) = f(1); v(ix,iy) = f(2);
    iy = iy + 1;
  end
  ix = ix+1; iy = 1;
end
 
tau = 0.01; % timestep size
Nsteps = 10000; 
figure('name','moving particle'); axis([-1.1 1.1 -1.1 1.1]); hold on;
quiver(x,y,u,v,2); title('{\bf force field}','fontsize',32);
pause;
movingparticle(A,p0,v0,tau,Nsteps);
hold off;