Advertisement
Slapoguzov

InterpolationNewton

Oct 5th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1.         static double Newtoon(double[] MasX, double[] MasY, int n, double x)
  2.         {
  3.             double result = MasY[0];
  4.             double[,] endDiffY0 = new double[n, n];                    //конечные разности y0. Первый столбец для y0, второй для y1, третий y2
  5.  
  6.             for (int i = 0; i < n - 1; i++)
  7.             {
  8.                 endDiffY0[0, i] = MasY[i + 1] - MasY[i];
  9.             }
  10.  
  11.             for (int i = 1; i < n; i++)                             //порядок конечной разности
  12.             {
  13.                 for (int j = 0; j < n - i; j++)                          //для каких y
  14.                 {
  15.                     endDiffY0[i, j] = endDiffY0[i - 1, j + 1] - endDiffY0[i - 1, j];
  16.                 }
  17.             }
  18.  
  19.             int fact = 1;
  20.             double q = (x - MasX[0]) / (MasX[1] - MasX[0]);
  21.             double q_f = q;
  22.             for (int i = 1; i < n; i++)
  23.             {
  24.  
  25.                 result += q_f * endDiffY0[i - 1, 0] / fact;
  26.                 q_f *= (q - i);
  27.                 fact *= (i + 1);
  28.             }
  29.  
  30.             return result;
  31.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement