Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static List<List<double>> CountSepaetedDifference(double[] fn)
- {
- List<List<double>> separatedDifference = new List<List<double>>();
- for (int i = 0; i < fn.Length; i++)
- {
- List <double> tmp = new List<double>();
- tmp.Add(fn[i]);
- separatedDifference.Add(tmp);
- }
- int n = fn.Length - 1;
- for (int i = 0; i < fn.Length - 1; i++)
- {
- for (int j = 0; j < n; j++)
- {
- separatedDifference[j].Add((separatedDifference[j+1][i] - separatedDifference[j][i]) / (i + 1) );
- }
- n--;
- }
- return separatedDifference;
- }
- static void Newton()
- {
- double[] xn = { 1, 2, 3, 4, 5 };
- double[] fn = { 1, 16, 81, 256, 625 };
- double x = 0;
- List<List<double>> separetedDifference = CountSepaetedDifference(fn);
- double Nn = 0;
- double multiplier = 1;
- for (int i = 0; i < xn.Length - 1; i++)
- {
- x = (xn[i] + xn[i + 1]) / 2;
- Nn = separetedDifference[0][0];
- multiplier = 1;
- for (int j = 0; j < xn.Length - 1; j++)
- {
- multiplier *= (x - xn[j]);
- Nn += separetedDifference[0][j + 1] * multiplier;
- }
- Console.WriteLine("{0} - {1} - {2}", x, Nn, x * x * x * x);
- }
- }
- static void Main(string[] args)
- {
- Newton();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement