1. ## gravitational differential

I'm trying to write a simple game engine with gravitation between players and various things, but when objects get rather close the linear approximations get direly inaccurate, and I wanted to be able to keep energy conserved.

So I'm trying to work out this problem here, as the first step before taking it into vector calculus, which I know nothing about:
$\frac{d^2x}{dt^2} = \frac{k}{x^2}$ (note that k = m2*G, because m1a = (m1*m2*g)/x^2, and we assume that mass 2 is held in place... somehow....)

I don't quite know what to do with it, when I tried working it out I got this:
$\int x^2*\frac {d^2x}{dt^2}\ dt = \int -k \ dt$
$\int x^2*\frac {d^2x}{dt} = -kt$
$\int \frac {d}{dt} (x^2)\ dx = -kt$

But I don't believe I can find the derivative of x^2 with respect to t like this....

I am only in high school calculus, but can generally get a good quick grasp of math-stuffs, especially if I need it for programming stuffs like this. >.> But if this doesn't qualify as a differential equation as I suspected, just PM me if you move it to another section.

I tried to take it a lot further with some substitutions and came up with some weird stuff with natural logs of negative numbers in it.
My logic is clearly screwy in how I try to manipulate the differentials, because if that worked, then so would this:
$\int \frac {d^2x}{dt^2}\ dt = \frac {dx}{dt}$
$\int \frac {d^2x}{dt} = \frac {dx}{dt}$
$\int \frac {d}{dt}\ dx = \frac {dx}{dt} \frac{d}{dt} \ \ \ \ (\frac {d}{dt}(1) = 0)$
$\int 0\ dx = C = \frac {dx}{dt}$
Which would imply that as long as an acceleration equation exists, velocity is constant, which definitely makes no sense.

 For those interested, here's my most accurate (and complicated) attempt at a system of equations to show the behavior I need to solve for position over time.
$\frac{d^2x}{dt^2} = \frac{k}{x^2 + y^2} * cos\left(cos^{-1}\left[\frac{x}{x^2+y^2}\right]\right)$
$\frac{d^2y}{dt^2} = \frac{k}{x^2 + y^2} * sin\left(cos^{-1}\left[\frac{x}{x^2+y^2}\right]\right)$
where k = G*m2

And any help drafting a complete system of equations to represent the behavior of n different particles gravitating toward one another, or the pointing out of any flaws in my current system (besides the fact that it only represents gravitation of one particle around another, stationary particle) would also be appreciated.

2. Since that method was worthless, and no one bothered helping before my question reached the next page, I tried integrating by parts. And I edited everything to use LaTeX after I noticed the tutorial, read it, and decided it was much easier to use than it initially looked from mouse-overs that displayed the code used, which I tried at first (for a moment or two) to use to learn it. >.> Sorry.

$\int x^2*\frac{d^2x}{dt^2}\ dt = -\int k\ dt$
$let\ v = x^2$

$dv = 2x\ dx$

$let\ du = \frac{d^2x}{dt^2}\ dt$
$u = \frac{dx}{dt}$
$\frac{dx}{dt}*x^2 - \int\frac{dx}{dt}*2x\ dx = -\int k\ dt$
$let\ v = 2x$

$dv = 2 dx$

$let\ du = \frac{dx}{dt} dx$
$u = \int \frac{dx}{dt}\ dx = ?$
Still nothing....

Anyone have any ideas here?

Also, if you're good at all this stuff, and can't figure out how or don't think there's a solution (I highly doubt this is the case, but no one's helping, so I guess that could be why.), say so. Or, you know, if you're gonna refuse to even begin to try to explain any of it like you think you must because I'm only in high school (Although you needn't, as I can look up any terms you use to find out what they mean / how they work; just give the correct terms for the procedures.).... I have other resources I can put more time into if I can be pretty sure that no one at the forum is going to help. Also, if it's in the wrong section, please tell me that and report it, so it can be moved to the right one. Thanks in advance.

3. Rewritting the equation as:

$x^2x''=k$

gives as solution:

$t+K_2=\sqrt{\frac{1}{K_1}-\frac{2k}{xK_1^2}}+ \frac{k}{K_1^{2/3}} ln\left[-k+x\cdot \left(K_1+\sqrt{K_1^2-\frac{2kK_1}{x}} \right)\right]$

Because of the following:

Originally Posted by Zizoo
Since that method was worthless, and no one bothered helping before my question reached the next page, I tried integrating by parts.

Anyone have any ideas here?

Also, if you're good at all this stuff, and can't figure out how or don't think there's a solution (I highly doubt this is the case, but no one's helping, so I guess that could be why.), say so. Or, you know, if you're gonna refuse to even begin to try to explain any of it like you think you must because I'm only in high school (Although you needn't, as I can look up any terms you use to find out what they mean / how they work; just give the correct terms for the procedures.).... I have other resources I can put more time into if I can be pretty sure that no one at the forum is going to help. Also, if it's in the wrong section, please tell me that and report it, so it can be moved to the right one. Thanks in advance.
I am not going in details on how to solve it. Be more polite in the future and people might be more eager to help.

4. Thank you very much, but I'm still gonna need some details this time around, since I'm not nearly done with the problem. I still need to take it into two dimensions later. xP

o.o I really didn't mean to be rude. I was indeed very blunt, and perhaps I got more than a tad impatient, but any rudeness was unintended. I'm sorry. After finally checking the dates, I see it's only been six days, but I hadn't thought too hard about any realistic expectations of when to receive an answer quantitatively, and simply knew it had felt like a long time, so I was trying to point out any reasons anyone might have read my problem and not answered and encourage them to ignore them and/or inform me of them. ^^;;;;; Likewise, my statement that the thread had reached the next page was simply meant to inform people of my reason for double-posting, which I avoid like the plague.

5. Originally Posted by Zizoo
[snip]
$\frac{d^2x}{dt^2} = \frac{k}{x^2}$ (note that k = m2*G, because m1a = (m1*m2*g)/x^2, and we assume that mass 2 is held in place... somehow....)

[snip]
Start by making the substitution $v = \frac{dx}{dt}$.

Then $\frac{d^2 x}{dt^2} = \frac{d}{dx} \left[\frac{v^2}{2}\right]$ and so your equation becomes

$\frac{d}{dx} \left[\frac{v^2}{2}\right] = \frac{k}{x^2} \Rightarrow \frac{v^2}{2} = - \frac{k}{x} + C \Rightarrow v = \pm \sqrt{A -\frac{2k}{x}}$.

Now you need to solve $\frac{dx}{dt} = \pm \sqrt{A -\frac{2k}{x}}$.

6. Originally Posted by mr fantastic
Start by making the substitution $v = \frac{dx}{dt}$.
Should we not include a C value here equal to v(0) like this: $v = \frac{dx}{dt} + v(0)$? I know I need to make sure my only unknown constants at the end are v(0) and x(0), and perhaps later I should try to allow for a(0), so that these can be plugged in to the equation in the simulation program.

Then $\frac{d^2 x}{dt^2} = \frac{d}{dx} \left[\frac{v^2}{2}\right]$ and so your equation becomes
Why do we say that $\frac{d^2 x}{dt^2} = \frac{d}{dx} \left[\frac{v^2}{2}\right]$ rather than $\frac{d^2 x}{dt^2} = \frac{d}{dx} \left[v\right]$?
I think that's wrong because $\frac{d}{dx}\left[\left(\frac{dx}{dt}\right)^2*\frac{1}{2}\right] = \frac{1}{2}\left(2\frac{dx}{dt}*\frac{d^2x}{dt^2}\ right) = \frac{dx}{dt} \frac{d^2x}{dt^2} \neq \frac{d^2x}{dt^2}$

Originally Posted by mr fantastic
$\frac{d}{dx} \left[\frac{v^2}{2}\right] = \frac{k}{x^2} \Rightarrow \frac{v^2}{2} = - \frac{k}{x} + C \Rightarrow v = \pm \sqrt{A -\frac{2k}{x}}$.

Now you need to solve $\frac{dx}{dt} = \pm \sqrt{A -\frac{2k}{x}}$.
I see here how you get A, but is there any way to have this 'A' in there now and still eventually bring it out to where the only constants we're using are x(0) and v(0)?

And Cooman, may I assume that you're K_1 and K_2 values are x(0) and v(0), and if so, which is which? Please elaborate, I beg of you.

And I'm gonna stop being so impatient now.... If it takes a few months to sort out the whole issue, so be it. I'll just make an effort to put this thread on the front page every now and again (probably not immediately after it falls from front page) with bumps until it's sorted out. I figure there are enough people here that hopefully a large number of people can work on this only as much as they care to in a few moments now and again without really getting wiped out on it, and it can still get done. >.> If you guys generally get very annoyed with me about this, lemme know, and I'll see what I can do, but this problem is one I most direly need sorted out if I'm going to finish writing my little game engine which I so enjoy. ^^

7. Some years ago I tried to solve the following problem [see image…]

Let’s indicate $x=0$ the ‘centre of mass’ of a ‘black hole’ and adopt a system of measure so that at the time $t=0$ is $x(0)=1, \frac{dx}{dt}(0)=0$ and $x(*)$ is the solution of …

$\frac {d^{2}x}{d t^{2}}= - \frac {1}{x^{2}}$ (1)

The ‘standard’ approach to (1) is a little uncomfortable and it is better to transform it, if possible, in an equation of order 1. Since the system is ‘loss free’, all the ‘gravitational energy’ must become ‘kinetic energy’ so that we can write…

$\frac{1}{2} \cdot m \cdot (\frac {dx}{dt})^{2}= \int_{1}^{x} \frac{m}{\xi^{2}}\cdot d\xi= m\cdot \frac {1-x}{x}$ (2)

… where m is the mass of the ‘material point’. From (2) it is easy to obtain…

$\frac {dx}{dt}= \pm \sqrt {\frac{1-x}{2x}}$ (3)

By observing the (3) we notice a ‘little surprise’ because in $x=0$ the $\frac{dx}{dt}$ has a ‘singularity’. Limiting the search in the interval 0 < x < 1, the (3) can be integrated in ‘standard fashion’ and we obtain…

$\int \sqrt \frac{1-x}{x}\cdot dx= \sqrt{2}\cdot t+c$ (4)

With little of patience we solve the integral at the first term and obtain, taking into account the ‘initial conditions’ , the following solution of (1)…

$\sqrt {x\cdot (1-x)} + \tan^{-1} \sqrt {\frac{1-x}{x}}= \sqrt{2}\cdot t$ (5)

The ‘material point’ meets the centre of the ‘black hole’ at the time…

$t_{0}= \frac {\pi}{2\cdot \sqrt{2}}$ (6)

A simple question now: what does it happen for t > to?… A very interesting question…

Kind regards

$\chi$ $\sigma$

8. Hmm... thanks. That is indeed interesting, but what does $\xi$ mean, and/or how are you able to make that substitution? >.> I'm not sure it'll help me with my game engine, since it will incorporate a variety of different opposing gravitational and static forces upon completion, but I'd like to know anyways. =3

Maybe after instantaneously acquiring an infinite amount of speed it jumps out of the entire universe! =O ... Not really, since the force at the point of singularity would be in a non-existent direction (direction from a point to itself), but still an amusing thought. =P It instantly stops cold in the center, where some sort of insane nuclear fusion occurs probably. >.>.... Now I wanna go study black holes....

9. Originally Posted by Zizoo
Why do we say that $\frac{d^2 x}{dt^2} = \frac{d}{dx} \left[\frac{v^2}{2}\right]$ rather than $\frac{d^2 x}{dt^2} = \frac{d}{dx} \left[v\right]$?
I think that's wrong because $\frac{d}{dx}\left[\left(\frac{dx}{dt}\right)^2*\frac{1}{2}\right] = \frac{1}{2}\left(2\frac{dx}{dt}*\frac{d^2x}{dt^2}\ right) = \frac{dx}{dt} \frac{d^2x}{dt^2} \neq \frac{d^2x}{dt^2}$
[snip]
I'm afraid it's you that is wrong. You seem to think that $\frac{d}{dx} \left( \frac{dx}{dt} \right) = \frac{d^2 x}{dt^2}$. It is not.

Proof of the result I gave:

$\frac{d^2 x}{dt^2} = \frac{d}{dt} \left[ \frac{dx}{dt} \right] = \frac{dv}{dt} = \frac{dv}{dx} \cdot \frac{dx}{dt} = \frac{dv}{dx} \cdot v = \frac{dv}{dx} \cdot \frac{d}{dv} \left[ \frac{v^2}{2} \right] = \frac{d}{dx} \left[ \frac{v^2}{2} \right]$.

This result is a well known and routine expression for acceleration. Part of your problem I think is that you're trying to solve a problem for which you currently lack the necessary mathematical tools to solve.

10. xP Sorry, I should've looked at it more carefully. Indeed, one of the roadblocks I found in one of my attempts to solve it was not knowing how to integrate dx/dt with respect to x. >.>

And perhaps you are right. I may just have to stop, and wait till later on in college courses in this realm, perhaps meanwhile only using the engine with air resistance, which I *do* have written in, but wanted to be able to turn off with some sort of power-up or switch in a game. I don't even really like using it though.... I like the awesome high speeds achievable when you take off those limiters, and I even wrote a pretty decent algorithm to use motion equations to determine collision, although as I said before it is currently only using linear approximations.... I could figure it out though. *insert amusing-looking, determined-yet-conflicted emoticon holding up fist here* xD

But yes, hopefully what you just posted will make more sense when I have more time to look at and interpret it, and maybe look up some stuff. Was letting my impatience get the better of me again there.... But now I have things I need to do that take precedence, sadly. =/

 Alright, I read it over and it makes perfect sense now. Very simple application of chain rule.... *had less than 20-30 seconds to look at it last time*

But now for the second part of my previous post. Can't we avoid using constants that aren't defined in terms of x(0) and v(0)?

11. Originally Posted by Zizoo
[snip]But now for the second part of my previous post. Can't we avoid using constants that aren't defined in terms of x(0) and v(0)?
You need boundary conditions to get a particular. What are your boundary conditions.

12. Isn't there a way I could avoid using methods dependent on explicit conditions for each case? I'd want a general means for finding the functions given *any* initial velocities and displacements, since these methods are going to be applied to varied situations continuously in the program, and I'm not sure how I'd come up with the second value for the boundary.... *had to look up boundary value problems on wikipedia just now* >_<

Oh! I think my particulars are predefined, rather than any boundaries. I just need a general equation for in terms of those particulars.... Although I'm not sure what is meant by 'particulars'.... *doesn't see a definition for it with respect to differential equations on wikipedia*... If there's another site with strict math definitions you know of, can you link me so I can look up any terms I don't get?

13. $t+K_2=x\sqrt{\frac{1}{K_1}-\frac{2k}{xK_1^2}}+ \frac{k}{K_1^{3/2}} ln\left[-k+x\cdot \left(K_1+\sqrt{K_1^2-\frac{2kK_1}{x}} \right)\right]$

Hello Zizoo,

It is coomast, not cooman . I'm sorry I couldn't come back earlier because I had a busy week. Anyway let's forget our older posts and try solving the problem. First a few remarks, the equation I presented had some typo's. I cleared them up and above is the right formula (missing x before the first root and the power is 3/2, not 2/3). Secondly the constants are not directly related to x(0) and v(0), they are integration constants which need to be found by the boundary conditions. Using v(0) will force you to calculate the derivative. OK, let's shed some light on the way to solve the equation. The method I use is by transforming it to a lower degree DE, comparable to what mr fantastic posted. So, substitute the following:

$u=x$
$v=x'$
$\frac{dv}{du}=\frac{x''}{x'}$

(these are new variables and are not related to velocity) giving:

$u^2v\frac{dv}{du}=k$

which can be solved by separation of the variables to:

$v=\sqrt{A-\frac{2k}{u}}$

Going now back to the original variables, we have:

$\frac{dx}{dt}=\sqrt{A-\frac{2k}{x}}$

or:

$\frac{dx}{\sqrt{A-\frac{2k}{x}}}=dt$

Solving this gives the formula I posted, after some algebra and renaming the constants. The velocity can be found by taking the derivative of this as (naming the function we have t=f(x)):

$v=\frac{dx}{dt}=\frac{1}{f'(x)}$

The accelaration can be obtained as:

$a=v\frac{dv}{dx}=\frac{1}{f'(x)}\frac{d}{dx}\left( \frac{1}{f'(x)}\right)=-\frac{f''(x)}{f'(x)^3}$

I didn't do these last derivations. If you now have as initial condition x(0)=C, you need to put that in the formula and the same for the velocity. Then it is possible to obtain the integration constants K1 and K2. This will not be easy...

Hope this helps so far.

coomast

14. Alright, this makes sense mostly, after a bit of mulling over on my part, but there's one problem.
Here:
Originally Posted by Coomast
$u^2v\frac{dv}{du}=k$
The 'k' should be '-k'.

Am I right to assume that this issue can be solved by replacing all instances of 'k' with '-k' in your final solution? Your final equation was the only one I wasn't able to figure out how you derived.... xP... Confusing complicated integral thingy.... After that though I think I might be able to solve for the integration constants according to your *very* helpful bit on the end there about reinterpretting it as an inverse function (make no mistake, the whole post was helpful =P). I never would have thought of that.

Oh and sorry about the name mistake. I may or may not have been very tired that day. I don't recall, but I spent a lot of time around then half-asleep.

15. Hello Zizoo

In case the constant is negative, you can savely switch the sign. It is a good thing that you think about this and not "just" make it negative. In some cases (not here) the integral becomes something different to solve.

coomast