# Solving for x. Do I require iterations?

I have the following expression (used in a computer program): $$f(x)=b^{{k}^{ax}}$$

where $k$ is a constant and $a$ and $b$ are given. I need to calculate the distance from this curve to a point $P: (c,d)$. The simple procedure would be to take the derivative of the equation

$$\frac{\partial(distance)}{\partial x}=\sqrt{(c-x)^2+(d-f(x))^2} = 0$$

That will get me the x of the curve that is closest to the point. The problem here is solving for x. The expression is quite complex (and out of my mathematical capacities) to be solved by me. I tried using Mathematica, but I didn't get the result using Solve's. Am I left with using iterations? I'd rather avoid that option, since I require some speed in the processing.

Note: Not sure of which tags to use.

-

Yes, this is the right approach.

A common trick when minimizing distance is to minimize distance squared instead, which has the same optimum but a much cleaner derivative.

You will get the equation

$$(x-c) + (b^{k^{ax}} - d)b^{k^{ax}}k^{ax} a\log b\log k = 0$$

and there is little hope of solving this equation for $x$ in closed form. Your best bet is to find a numerical solution iteratively using Newton's method. If you have to repeat the calculation many times, with $a,b,c,d$ changing only slightly each time, you will want to use the previous $x$ as your initial guess for computing the next $x$, and Newton's method will likely converge in very few iterations.

-

Depending on the values of $a,b,k$, this is likely to be a very rapidly growing function. If so, it is (almost) vertical, so the perpendicular is (almost) horizontal. In this approximation, the shortest distance will be when $f(x)=d$, so you can just say

$d=b^{k^{ax}}\\ \log d=k^{ax} \log b \\ \log \log d=ax \log k + \log \log b \\ x=\frac{\log \log d - \log \log b}{a \log k}$

-