Computer Programming/Physics/Position of an accelerating body function

From testwiki
Jump to navigation Jump to search

Wikisource:Source code

The position of an accelerating body can be described by a mathematical function 𝐬(t). The generalized function can be attained by using the Taylor series

𝐬(t+t0)=tnn!𝐬(n)(t0),

where 𝐬(n) is the nth derivative of 𝐬:

  • 𝐬(0)=d0𝐬dt0=𝐬
  • 𝐬(1)=d1𝐬dt1=𝐯
  • 𝐬(2)=d2𝐬dt2=𝐚
  • etc.

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

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

s(t)=10!𝐬0+t1!𝐬0(1)+t22!𝐬0(2)

or

𝐬(t)=𝐬0+𝐯0t+12𝐚t2

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)=s0
or
s(t)=t00!s(0)(t0=0)
  • Constant Velocity
v(t)=v0
s(t)=vdt=v0dt
s(t)=v0t+s0
or
s(t)=t00!s(0)(t0=0)+t11!s(1)(t0=0)
  • Constant Acceleration
a(t)=a0
v(t)=adt=a0dt
v(t)=a0t+v0
s(t)=vdt=(a0t+v0)dt
s(t)=12a0t2+v0t+s0
or
s(t)=t00!s(0)(t0=0)+t11!s(1)(t0=0)+t22!s(2)(t0=0)
  • Constant Rate of Change of Acceleration
a(1)(t)=a0(1)
a(t)=a(1)dt=a0(1)dt
a(t)=a0(1)t+a0
v(t)=adt=(a0(1)t+a0)dt
v(t)=12a0(1)t2+a0t+v0
s(t)=vdt=(12a0(1)t2+a0t+v0)dt
s(t)=16a0(1)t3+12a0t2+v0t+s0
or
s(t)=t00!s(0)(t0=0)+t11!s(1)(t0=0)+t22!s(2)(t0=0)+t33!s(3)(t0=0)
  • etc.

Template:BookCat