Advertisement
myname0

Lagrange

Nov 7th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. static void LagrangePolinomial()
  2.         {
  3.             double[] xn = { 1, 2, 3, 4, 5 };
  4.             double[] fn = { 1, 16, 81, 256, 625 };
  5.             double x = 0;
  6.             double Sum = 0;
  7.             double multiplier = 1;
  8.             for (int i = 0; i < 4; i++)
  9.             {
  10.                 x = (xn[i + 1] + xn[i]) / 2;
  11.                 Sum = 0;
  12.                 for(int j = 0; j < 5; j++)
  13.                 {
  14.                     multiplier = 1;
  15.                     for (int k = 0; k < 5; k++)
  16.                     {
  17.                         if(k == j ) continue;
  18.                         multiplier *= (x - xn[k]) / (xn[j] - xn[k]);
  19.                     }
  20.                     Sum += fn[j] * multiplier;
  21.                 }
  22.                 Console.WriteLine("{0}  -  {1}  -  {2}", x, Sum, x * x * x * x);
  23.             }
  24.         }
  25.  
  26.         static void Main(string[] args)
  27.         {
  28.             LagrangePolinomial();
  29.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement