for i=1:1:351
initial_f=[0 0 (i-51)*1e-6 0 0 0];
t=(0:10:10000)*1e-15;
options=odeset('reltol',1e-15,'abstol',1e-20);
[t,f]=ode15s('lorentz_force',t,initial_f,options);
F=zeros(1001,6,i);
F(:,:,i)=f(i);
X=F(:,1,:);Y=F(:,2,:);Z=F(:,3,:);
PX=F(:,4,:);PY=F(:,5,:);PZ=F(:,6,:);
p_x=PX(1001,:);
p_y=PY(1001,:);
p_z=PZ(1001,:);
p_r= sqrt((p_x.^2)+(p_y.^2)+(p_z.^2));
Energy_total=sqrt(((p_r).^2).*(c^2)+((m^2)*(c^4)));
Energy_initial=m*c^2;
Energy_gain=Energy_total-Energy_initial;
plot((i-51)*1e-6,Energy_gain./e)
xlabel ('z_0 (m)')
ylabel ('Energy Gain (eV)')
end
end