in reply to OT:Math problem: Grids and conical sections.
That said, you have 4 measurements, and you need to figure out 4 variables - the x-coordinate of the peak, the y-coordinate of the peak, the height of the peak, and the slope of the mountain. That means that normally (barring degenerate cases, such as the peak being in the middle) there should be a unique answer. (Or a finite number of them - however a glance at this situation suggests that it will normally be unique.) But that doesn't make it easy to find.
I would have to resort in this case to numerical approximations. You can use brute force guessing to come up with a good combination. Or you can try to be clever.
If I wanted an easy answer to code, I'd use brute force. If I wanted to be clever, I'd use Newton's method.
To refresh your memory, Newton's method works like this. For x near x0, f(x) is approximately
f(x0) + f'(x0)*(x - x0)Now suppose that we want k = f(x). Then if x is close to x0 then we expect the above approximation to be close to k. Which means that x - x0 is going to be close to:
x0 + (f'(x0))**(-1) * (k - f(x0))So Newton's method starts with finding one approximation x0, using the above to find a hopefully better approximation x1, which is used to improve to x2 and so on.
If you start off a long ways away from an approximation, you can still use Newton's method. What you do is check how good an approximation you have. If in a single step your approximation gets worse, then that is because you are travelling farther than the tangent line approximation is good for. But you know that if you just go a short distance in that direction, you should get better. So try travelling in that direction half the distance, 1/4, 1/8 and so on until you find a fraction that is an actual improvement. After improving a few times, then you should get close enough to a real answer that Newton's method just works for you.
Now I see you objecting that you can do this for functions of one variable, and here you have functions of many. Well while it seems more complex, this works for functions of many variables as well! All that you have to remember is that x is a vector and f'(x) is a matrix.
Which matrix? It is a mess of partial derivatives. I'm too lazy to type in what mess of which partial derivatives, but it can be found written in lots of places. Also it is trivial to figure out the terms by remembering two facts. The first is that the tangent approximation has to hold in every output dimensions for changes in any one input dimension. The second is the rule for matrix multiplication. When you write those two down, it is easy to see that only one set of partial derivatives can possibly work.
To figure out the answer, you'll also need to invert lots of matrices. If you don't want to use PDL, then remember that the fastest way to do invert M is to write [M | I] (where I is the identity matrix) and then apply row operations (multiply row by scalar, swap rows, add multiple of one row to another) to turn that into [I | N]. When you have done so, then N is the inverse of M. (This requires an average of O(n**3) operations. The well-known formula is exponential in the dimension.)
Of course Cramer's rule may be faster for you to program, and it isn't THAT much slower in 4 dimensions...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: OT:Math problem: Grids and conical sections.
by BrowserUk (Patriarch) on Nov 24, 2005 at 09:33 UTC | |
by tilly (Archbishop) on Nov 24, 2005 at 19:17 UTC | |
by tilly (Archbishop) on Nov 25, 2005 at 07:18 UTC |