# Computer Programming/Physics/Position of an accelerating body function

The position of an accelerating body can be described by a mathematical function $\mathbf {s} (t)$ . The generalized function can be attained by using the Taylor series

$\mathbf {s} (t+t_{0})=\sum {\frac {t^{n}}{n!}}\mathbf {s} ^{(n)}(t_{0})$ ,

where $\mathbf {s} ^{(n)}$ is the $nth$ derivative of $\mathbf {s}$ :

• $\mathbf {s} ^{(0)}={\frac {d^{0}\mathbf {s} }{dt^{0}}}=\mathbf {s}$ • $\mathbf {s} ^{(1)}={\frac {d^{1}\mathbf {s} }{dt^{1}}}=\mathbf {v}$ • $\mathbf {s} ^{(2)}={\frac {d^{2}\mathbf {s} }{dt^{2}}}=\mathbf {a}$ • etc.

The accuracy of this function depends on the number of terms used as ${\frac {1}{n!}}$ decreases rapidly. Additionally, the time $t$ can be synchronized such that $t_{0}=0$ (Maclaurin series).

Note that for a constant acceleration most of the terms become zero and we're left with

$s(t)={\frac {1}{0!}}\mathbf {s} _{0}+{\frac {t}{1!}}\mathbf {s} _{0}^{(1)}+{\frac {t^{2}}{2!}}\mathbf {s} _{0}^{(2)}$ or

$\mathbf {s} (t)=\mathbf {s} _{0}+\mathbf {v} _{0}t+{\frac {1}{2}}\mathbf {a} t^{2}$ ## C++

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

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
$s(t)=s_{0}$ or
$s(t)={\frac {t^{0}}{0!}}s^{(0)}(t_{0}=0)$ • Constant Velocity
$v(t)=v_{0}$ $s(t)=\int vdt=\int v_{0}dt$ $s(t)=v_{0}t+s_{0}$ or
$s(t)={\frac {t^{0}}{0!}}s^{(0)}(t_{0}=0)+{\frac {t^{1}}{1!}}s^{(1)}(t_{0}=0)$ • Constant Acceleration
$a(t)=a_{0}$ $v(t)=\int adt=\int a_{0}dt$ $v(t)=a_{0}t+v_{0}$ $s(t)=\int vdt=\int (a_{0}t+v_{0})dt$ $s(t)={\frac {1}{2}}a_{0}t^{2}+v_{0}t+s_{0}$ or
$s(t)={\frac {t^{0}}{0!}}s^{(0)}(t_{0}=0)+{\frac {t^{1}}{1!}}s^{(1)}(t_{0}=0)+{\frac {t^{2}}{2!}}s^{(2)}(t_{0}=0)$ • Constant Rate of Change of Acceleration
$a^{(1)}(t)=a_{0}^{(1)}$ $a(t)=\int a^{(1)}dt=\int a_{0}^{(1)}dt$ $a(t)=a_{0}^{(1)}t+a_{0}$ $v(t)=\int adt=\int (a_{0}^{(1)}t+a_{0})dt$ $v(t)={\frac {1}{2}}a_{0}^{(1)}t^{2}+a_{0}t+v_{0}$ $s(t)=\int vdt=\int ({\frac {1}{2}}a_{0}^{(1)}t^{2}+a_{0}t+v_{0})dt$ $s(t)={\frac {1}{6}}a_{0}^{(1)}t^{3}+{\frac {1}{2}}a_{0}t^{2}+v_{0}t+s_{0}$ or
$s(t)={\frac {t^{0}}{0!}}s^{(0)}(t_{0}=0)+{\frac {t^{1}}{1!}}s^{(1)}(t_{0}=0)+{\frac {t^{2}}{2!}}s^{(2)}(t_{0}=0)+{\frac {t^{3}}{3!}}s^{(3)}(t_{0}=0)$ • etc.