Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void LagrangePolinomial()
- {
- double[] xn = { 1, 2, 3, 4, 5 };
- double[] fn = { 1, 16, 81, 256, 625 };
- double x = 0;
- double Sum = 0;
- double multiplier = 1;
- for (int i = 0; i < 4; i++)
- {
- x = (xn[i + 1] + xn[i]) / 2;
- Sum = 0;
- for(int j = 0; j < 5; j++)
- {
- multiplier = 1;
- for (int k = 0; k < 5; k++)
- {
- if(k == j ) continue;
- multiplier *= (x - xn[k]) / (xn[j] - xn[k]);
- }
- Sum += fn[j] * multiplier;
- }
- Console.WriteLine("{0} - {1} - {2}", x, Sum, x * x * x * x);
- }
- }
- static void Main(string[] args)
- {
- LagrangePolinomial();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement