1

私はついに曲線から走る点までの距離の公式を手に入れました: approx = 2 * (b * (Math.Log(a) * (Math.Log(k) * Math.Pow(k, (b * cycleX))) * Math.Pow(a, (Math.Pow(k, (b * cycleX)))) * (Math.Pow(a, (Math.Pow(k, (b * cycleX))))) - points[i].Y) + cycleX - points[i].X);

したがって、approx0に近づくにつれて、cycleXはポイントまでの距離を計算するための正しい座標を与えてくれます。

ここでの唯一の問題は、を変更する方法を定義することcycleXです。一連のif'を使用してみましたが、それらを使用するapproxと、正の数(負の数から来る)にジャンプすることがあります。cycleXの値を正しく変更するにはどうすればよいですか?

注:通常、-1から1の範囲内で何かを取得するには、0.0001まで下げる必要があります。

4

1 に答える 1

0

For this kind of problem, it's often useful to know about Newton's method:

Of course, the forumula for that is

x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}. \,!

Of course, besides the fact that for some functions this quite unstable (I don't expect yours to be, though), implemented purely for your case, it would mean you would need to calculate yet another derivative (of your derivative)! However, I think for your case, you might be able to just approximate the derivative.

You didn't mention the language your implementation would eventually be in, so I'll just use javascript for convenience.

To estimate your derivative, simply choose a deltaX that would be convenient.

So if you have a function

var df = function (cycleX) {
  return 2 * (b * (Math.log(a) * (Math.log(k) * Math.pow(k, (b * cycleX))) * Math.pow(a, (Math.pow(k, (b * cycleX)))) * (Math.pow(a, (Math.pow(k, (b * cycleX))))) - Y) + cycleX - X);
};

you can estimate it's derivative via

  y = df(cycleX);
  y1 = (df(cycleX + deltaX) - y) / deltaX;

And then proceed via.

  cycleXnew = cycleX - y / y1;

And then it's just a matter of looping until it converges (or not).

See example jsFiddle: http://jsfiddle.net/jfcox/3wRtj/

Edit: I give no guarantees as to how fast it might converge or even how well an estimated derivative would work with respect to Newton's method. For the parameters I've tried given your function f(x) = a^(k^(bx)), it seems to work well, but I haven't tried much.

Edit II. Of course, the above jsFiddle also assumes only a single solution that we'd need to search for.

于 2013-02-03T00:01:36.860 に答える