Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm fairly new to Mathematica. I'm trying to test my C++ implementation of a fourth order Runge Kutta method for Newton's equations of motion. I want to test my integrator when the applied force is dependant on the position. I tried to implement Newton's equations of motion in Mathematica as below:

iMass = 4
iVel0 = {1.0, 1.0, 1.0}
iTime = 1.0
iMagn = Dot[iPos, iPos]^0.5
iForce = ((12.3/iMagn) - 1.2)*Normalize[iPos]
  (* Applied force is 12.3 / distance from 0 0 1.2 minus 1.2 and pointing towards 0,0,0 *)
iAccel = iForce/iMass
iVel = iVel0 + Integrate[iAccel, time]
iPos = {0.0, 10000, 0.0} + Integrate[iVel, time]}]

Mathematica ran for a couple of hours until I aborted the calculation.

How can I get Mathematica to integrate Newton's equations of motion when the applied force is a function of position?

share
    
Possible duplicate –  RunnyKine Feb 15 at 17:01

1 Answer 1

up vote 3 down vote accepted
iMass = 4;
iVel0 = {1.0, 1.0, 1.0};
iTime = 1.0;
iMagn = Dot[iPos[time], iPos[time]]^0.5;
iForce = ((12.3/iMagn) - 1.2)*Normalize[iPos[time]];
iAccel = iForce/iMass;
iPos0 = {0.0, 10000, 0.0};

sol = 
  NDSolve[
   {iPos''[time] == iAccel, iPos'[iTime] == iVel0, iPos[iTime] == iPos0}, 
   iPos, {time, iTime, 10}]
ParametricPlot3D[Evaluate[iPos[time] /. sol], {time, iTime, 10}, PlotRange -> All]
share

This site is currently not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .