$x_{n+1}=x_n - f(x_n)\frac{x_n - x_{n-1}}{f(x_n)-f(x_{n-1})}$
で逆関数の値を事前に計算し, 後に線形補間で求めるメモ.
C#のプログラム. 初期値はx0=0.0, x1=1.0.
delegate double Func(double x); static double estimate(Func f, double x0, double x1, double epsilon) { int count = 0; double x2; while(epsilon < Math.Abs(f(x1))) { double d = f(x1)-f(x0); if(Math.Abs(d) < 1.0e-200) { break; } x2 = x1 - f(x1)*(x1-x0)/d; x0 = x1; x1 = x2; if(100 < ++count) { break; } } return x1; } static float[] createSampleTable(int resolution, Func f, double epsilon) { float inv = 1.0f/resolution; float[] table = new float[resolution+1]; for(int i = 0; i <= resolution; ++i) { float v = i*inv; double estimated = estimate((double x)=>f(x)-v, 0.0, 1.0, epsilon); table[i] = (float)estimated; } return table; }
0 件のコメント:
コメントを投稿