"Implement verlet algorithm for scattering of a charged particle q by a stationary charge Q at (xQ,yQ) in 2D "
L=10;(*length of simulation box*)
(*
(* boundary values *)
L=10;(*length of simulation box*)
{x0,y0,z0}={0.0,L/2.0,L/2.0};
v0=1;r20=L/2.0;
theta1=45Degree;theta2=45Degree;
phi1=45Degree;phi2=45Degree;
T=Sqrt[(2.0L/0.1)];
(* end of boundary values *)
*)

verletModule[v0_,theta1_,theta2_,x0_,y0_,v0_,r20_,Nstep_,q_,Q_]:=Module[{},
T=Sqrt[(2.0L)/0.1];
k=1;m=1.0;
(* boundary and initial conditions *)
r2={r20*Sin[theta2],r20*Cos[theta2]};(*fixed location of Q *)
{x[0],y[0]}={x0,y0}; (*initial location of q *)
{vx[0],vy[0]}={v0*Sin[theta1],v0*Cos[theta1]}; (*initial velocity of q *)
(*end of boundary and initial condition*)

tinit=0.0;tlast=T;
Deltat=(tlast-tinit)/Nstep;

R[n_]:=Norm[({x[n],y[n]}-r2)];(*distance between q and Q*)
Rsq[n_]:=R[n]^2;(*distance sq between q and Q*)
rcap[n_]:=({x[n],y[n]}-r2)/R[n];
ycap={0,1};xcap={1,0};
ax[n_]:=(k*q*Q/m)(rcap[n].xcap)/Rsq[n];
ay[n_]:=(k*q*Q/m)(rcap[n].ycap)/Rsq[n];

For[n=0,n≤Nstep-1,n++,
x[n+1]=x[n]+vx[n]*Deltat+0.5*ax[n]*Deltat^2;
vx[n+1]=vx[n]+0.5*(ax[n]+ax[n+1])*Deltat;

y[n+1]=y[n]+vy[n]*Deltat+0.5*ay[n]*Deltat^2;
vy[n+1]=vy[n]+0.5*(ay[n]+ay[n+1])*Deltat;
(*Print[vy[n+1]];*)
];(*end for i*)

txy:=Table[{x[n],y[n]},{n,0,Nstep}];
xrange:={Max[{Max[txy],Norm[r2]}],Min[{Min[txy],Norm[r2]}]};
yrange:={Max[{Max[txy],Norm[r2]}],Min[{Min[txy],Norm[r2]}]};
(*plotrange:={{-xrange,xrange},{-yrange,yrange},{-zrange,zrange}};*)
plotrange:={xrange,yrange};
lptxy:=ListPointPlot3D[txy,PlotRange->plotrange,PlotLabel->"trajactory in 2D space"];
ttv:=Table[{n*Deltat,Sqrt[vy[n]^2+vx[n]^2]},{n,0,Nstep}];
lptttv:=ListPlot[ttv,Joined->True,Mesh->All,PlotRange->All,PlotLabel->"v vs. t"];
(*Print[lptxy];
Print[lptttv];*)
lptQ:=ListPlot[{r2},PlotStyle->{PointSize[Large],Red},PlotRange->plotrange];
Manipulate[
ttake=Take[txy,{1,n}];
lpttake=ListPlot[ttake,AspectRatio->1,Axes->True,AxesLabel->{x,y,z},
PlotRange->plotrange,PlotLabel->"trajactory in 2D space"<>";time ="<>ToString[n*Deltat]];
Show[lpttake,lptQ]
,{n,1,Nstep,1}]
];(*end module*)

Manipulate[verletModule[v0,theta1,theta2,x0,y0,v0,r20,Nstep,q,Q],{v0,1},
{x0,0},{y0,0},{v0,1},{theta1,45Degree},
{r20,10},{theta2,30 Degree},{q,1},{Q,1},{Nstep,200}]

plotrange

Max[txyz]