# Am I correct? Distance when velocity depends on position

I hope I'm in the right place to be asking this: I'm looking for somebody that knows better than I who can verify whether or not I've done things correctly. In trying to implement a feature for a game I'm working on, I've come up to the following problem (I apologize if my notation/terms are off, I'm strictly amateur):

Suppose I have an object that is moving across a 1D line over a period of time where its position on the line determines its instantaneous velocity like so:

$$V(x) = v_i + { x \Delta v \over L}$$

Where $V$ is velocity as a function of the position, $L$ is the length of the line, $v_i$ is the velocity of the object at the beginning of the line (when $x = 0$) and $\Delta v$ is the difference between the velocity at the end of the line (when $x = L$) and the velocity at the beginning.

I want to figure out a function $X(t)$ to determine the position of the object given an amount of time using the above formula for velocity, which itself depends on the position. Is simply substituting $x = X(t)$ and attempting to integrate valid? (I've just started learning calculus so I'm not at all confident in what I'm doing)

$$V(X(t)) = v_i + { X(t) \Delta v \over L}$$

$$X(t) = \int(v_i + { X(t) \Delta v \over L})\,dt$$

Once I tried solving I simply got:

$$X(t) = {tv_iL \over L - t\Delta v}$$

Is this correct? I expected some terms to end up with exponents or something more complicated, but the numbers I've tested seem to be alright. It kind of seems to me like I've just multiplied velocity times time, but I thought velocity not being constant would make that incorrect. Or maybe I've just been staring at the screen too long?

Corrections and insights appreciated, and thanks for taking the time.

Followup:

I programmed some tests and obtained the following results

Given: Length = 120, vi = 100, vf = 50; starting at position 0 and moving for time 5

• Approximation: 210.1165 @ dT = 0.0005 x timesteps = 10000
• My Formula: 162.1622
• E.O.'s Formula: 210.116524478485

And now I'm off to learn about differential equations!

• Can you give the physical context ? – Tony Piccolo Dec 13 '13 at 8:49
• How do you mean? Like a physical analog? Since this if for a game I'm afraid there really isn't one; the best I can describe it as is in the question: an object moving across a line over a period of time where the object's velocity depends on its position on the line. – Roland Dec 13 '13 at 9:00
• @Roland. Are you sure that the first thing to do would to be to look at the velocity. I have the feeling that the velocity must be written as an ordinary differential equation with boundary conditions. – Claude Leibovici Dec 13 '13 at 9:12
• @ClaudeLeibovici - I'm note sure at all. I started with velocity since it was the only thing I could think of that I could fully define, and integrating seemed like the correct solution. Since I'm barely starting calculus could you elaborate on what "an ordinary differential equation with boundary conditions" might mean in my context? – Roland Dec 13 '13 at 9:18

Let us first rewrite $V$ as $\displaystyle\frac{dx}{dt}$. For generality we will replace the coefficients with $a$ and $b$. Then your equation becomes $$\frac{dx}{dt}=a+bx$$ We can rearrange this to get $$\frac{1}{a/b+x}\frac{dx}{dt}=b$$ We then integrate both sides with respect to $t$ \begin{align*}\int\frac{1}{a/b+x}\frac{dx}{dt}dt&=\int b dt \\ \int\frac{1}{a/b+x}dx&=bt+c \\ \\ \log(a/b+x)&=bt+c \\\\ \frac ab+x&=e^{bt+c} \\ x&=Ae^{bt}-\frac ab \\\end{align*} We want $x(0)=x_0$ so $$x_0=Ae^0-\frac ab\to A=x_0+\frac ab$$ Therefore your general equation is $$x=\left(x_0+\frac ab\right)e^{bt}-\frac ab$$ Edit: In your particular case the equation is $$x=\left(x_0+\frac{v_i L}{\Delta v}\right)e^{t\Delta v/L}-\frac{v_i L}{\Delta v}$$ Edit 2: As was pointed out in the comments, this is a solution for $\Delta v\ne0$. In the case that $\Delta v=0$ we get the following solution \begin{align*}\frac{dx}{dt}&=a \\ \int\frac{dx}{dt}dt&=\int adt \\ x&=ax+c \\ x&=ax+x_0\end{align*} So your solution when $\Delta v=0$ is therefore $$x=v_it+x_0$$
• @Roland in your case $a=v_i$ and $b=\frac{\Delta V}{L}$. Note that we can rewrite $V$ as $\frac{dx}{dt}$ because the definition of velocity is the change in position with respect to time i.e. $\frac{dx}{dt}$. You can thus differentiate $x$ to see that the solution does indeed satisfy your conditions. – E.O. Dec 13 '13 at 10:00
• Thanks for the edit, it helps to connect things but reveals a problem that I can't resolve. If the velocities at the beginning and end of the line are equal, the answer should resolve to a simple $x = vt$, but with your final equation I'm going to get $\Delta v = 0$ and those divisions will be undefined. Can you account for this? – Roland Dec 13 '13 at 10:24
• After having run a few tests - Wow. That's just beautiful. A quick followup question if I may: if the object crosses a certain position I need to find at what point in time the object did so, I should be able to solve your equation for $t$ somehow and expect that to be it, correct? Or is there a simpler way? (should this be a separate question?) – Roland Dec 13 '13 at 17:17