3

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?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
RichardBruce
  • 219
  • 1
  • 4

1 Answers1

3
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]
m_goldberg
  • 107,779
  • 16
  • 103
  • 257
qwerty
  • 1,199
  • 1
  • 7
  • 7