Advertisement
Ochkasty_Dino

Методы вычислений (лагранжа)

Sep 28th, 2020 (edited)
1,089
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Lagranzh
  8. {
  9.     class Program
  10.     {
  11.         static double funct(double xi)
  12.         {
  13.             return xi * xi * xi / 4;
  14.         }
  15.        
  16.         static void Main(string[] args)
  17.         {
  18.             double y;
  19.             double sum = 0;
  20.             double pr = 1;
  21.  
  22.             Console.WriteLine("Please, enter number of intermediate values");
  23.             int n = int.Parse(Console.ReadLine());
  24.  
  25.             List<double> ixi = new List<double>();
  26.  
  27.             for(int i=0;i<n;i++)
  28.             {
  29.                 Console.WriteLine("Enter {0} intermediate value", i);
  30.                 double iks = Convert.ToDouble(Console.ReadLine());
  31.                 ixi.Add(iks);
  32.             }
  33.  
  34.             Console.WriteLine("Please enter the x = ");
  35.             double x = double.Parse(Console.ReadLine());
  36.  
  37.  
  38.             for (int i=0;i<ixi.Count;i++)
  39.             {
  40.                 y = funct(ixi[i]);
  41.                 for (int j=0;j<n;j++)
  42.                 {
  43.                     if (i != j)
  44.                     {
  45.                         pr *= (x - ixi[j]) / (ixi[i] - ixi[j]);
  46.                     }
  47.                 }
  48.                 sum += y * pr;
  49.                 pr = 1;
  50.             }
  51.             Console.WriteLine();
  52.             Console.WriteLine("{0}", sum);
  53.         }
  54.     }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement