Computer Programming/Physics/Position of an accelerating body function
From Wikibooks, open books for an open world
< Computer Programming  Physics(Redirected from Computer programming/Physics/Position of an accelerating body function)
The position of an accelerating body can be described by a mathematical function . The generalized function can be attained by using the Taylor series
 ,
where is the derivative of :

 etc.
The accuracy of this function depends on the number of terms used as decreases rapidly. Additionally, the time can be synchronized such that (Maclaurin series).
Note that for a constant acceleration most of the terms become zero and we're left with
or
C++[edit]
template<class Vector,class Number>
Vector PositionAcceleratingBody(Vector *s0,Number t,size_t Accuracy)
{
Vector s(0); //set to zero if int, float, etc. or invoke the
// "set to zero" constructor for a class
Number factor(1);//0!==1 and t^0==1
for(size_t n(0);n<Accuracy;n++)
{
if(n)factor*=(t/n);//0!==1 and t^0==1
s+=(factor*s0[n]); //s0 is the array of nth derivatives of s
// at t=t0=0
}
return s;
}
Justification for Using the Taylor Series[edit]
The Taylor series can be derived by systematically selecting which of our variables is a constant and then extrapolating that to the infinite limit.
 Constant Position

 or
 Constant Velocity

 or
 Constant Acceleration

 or
 Constant Rate of Change of Acceleration

 or
 etc.