2021-07-11 14:43:36 +02:00
|
|
|
function ParticleDynamicalQuantities = solver(this, InitialPosition, InitialVelocity)
|
|
|
|
|
2021-06-29 15:44:28 +02:00
|
|
|
if this.Gravity
|
2021-07-03 10:19:27 +02:00
|
|
|
g = [0,0,-Helper.PhysicsConstants.GravitationalAcceleration];
|
2021-06-29 15:44:28 +02:00
|
|
|
else
|
|
|
|
g = 0;
|
|
|
|
end
|
2021-07-11 14:43:36 +02:00
|
|
|
|
|
|
|
ParticleDynamicalQuantities = zeros(int64(this.SimulationTime/this.TimeStep),6);
|
|
|
|
for i=1:int64(this.SimulationTime/this.TimeStep)
|
2021-06-29 15:44:28 +02:00
|
|
|
|
2021-07-11 14:43:36 +02:00
|
|
|
ParticleDynamicalQuantities(i,1:3) = InitialPosition;
|
|
|
|
ParticleDynamicalQuantities(i,4:6) = InitialVelocity;
|
2021-07-14 20:07:22 +02:00
|
|
|
|
2021-07-11 14:43:36 +02:00
|
|
|
rt = InitialPosition;
|
|
|
|
vt = InitialVelocity;
|
2021-06-29 15:44:28 +02:00
|
|
|
|
2021-07-11 14:43:36 +02:00
|
|
|
ga1 = this.calculateTotalAcceleration(rt,vt) + g;
|
|
|
|
gv1 = vt .* this.TimeStep;
|
|
|
|
rt = rt + 0.5 * gv1;
|
|
|
|
vt = vt + 0.5 * ga1 .* this.TimeStep;
|
2021-06-29 15:44:28 +02:00
|
|
|
|
2021-07-11 14:43:36 +02:00
|
|
|
ga2 = this.calculateTotalAcceleration(rt,vt) + g;
|
|
|
|
gv2 = vt .* this.TimeStep;
|
|
|
|
rt = rt + 0.5 * gv2;
|
2021-07-14 20:07:22 +02:00
|
|
|
vt = vt + 0.5 * ga2 .* this.TimeStep;
|
2021-06-29 15:44:28 +02:00
|
|
|
|
2021-07-11 14:43:36 +02:00
|
|
|
ga3 = this.calculateTotalAcceleration(rt,vt) + g;
|
|
|
|
gv3 = vt .* this.TimeStep;
|
|
|
|
rt = rt + 0.5 * gv3;
|
|
|
|
vt = vt + ga3 .* this.TimeStep;
|
2021-06-29 15:44:28 +02:00
|
|
|
|
2021-07-11 14:43:36 +02:00
|
|
|
ga4 = this.calculateTotalAcceleration(rt,vt) + g;
|
|
|
|
gv4 = vt .* this.TimeStep;
|
2021-06-29 15:44:28 +02:00
|
|
|
|
2021-07-11 14:43:36 +02:00
|
|
|
InitialPosition = InitialPosition + (gv1+2*(gv2+gv3)+gv4)./6;
|
|
|
|
InitialVelocity = InitialVelocity + this.TimeStep*(ga1+2*(ga2+ga3)+ga4)./6;
|
2021-06-29 15:44:28 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|