Fundamentals of Iterative Prediction with Varying Force
It is rare to have a force which is perfectly constant, and iterative analysis of more realistic varying-force systems is substantially more complicated. A toy model demonstrates how programs may be written to analyze these systems.
Main Idea
The physics of iterative prediction with varying force is the same as for prediction with constant force, but it is necessary to generalize the mathematical expressions, which adds complexity to the code.
A Mathematical Model
To begin with, consider a one dimensional force, which may vary with both as a function of time and/or dependent variables such as position and velocity. Then we write this as [math]\displaystyle{ F(t,x,v) }[/math]. Now, using the momentum principle, we know that [math]\displaystyle{ F = \frac{\text{d}p}{\text{d}t} }[/math], which in discrete terms is [math]\displaystyle{ \Delta p = F\Delta t }[/math].
Just as with a constant force, this lets us write out for some iteration at [math]\displaystyle{ (t_0,x_0,v_0) }[/math] that
[math]\displaystyle{ p_{final} = p_{initial} + F(t_0,x_0,v_0)\Delta t }[/math]
Which we combine with kinematics to produce a new set of variables [math]\displaystyle{ (t_1,x_1,v_1) }[/math]. The difference we now have is that whereas before [math]\displaystyle{ F(t_0,x_0,v_0) = F(t_1,x_1,v_1) }[/math], we must now recalculate [math]\displaystyle{ F(t_1,x_1,v_1) }[/math] using the relevant formula. This will take the form of an extra step in each iteration. It is important to note that although we write the force as a function of all of these variables, in most cases it will only depend upon one of them. In a spring, for example, we will see that [math]\displaystyle{ F(t,x,v) = F(x) }[/math], meaning that only the position is necessary to compute the force.
A Computational Implementation
https://trinket.io/python/a93745098e (WIP)