Advertisement
Ochkasty_Dino

Methods_NewTon

Oct 7th, 2020
829
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 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 MetVich_Belous_Nyuton
  8. {
  9.     class Program
  10.     {
  11.         static double funct(double x)
  12.         {
  13.             return x * x * x / 4;
  14.         }
  15.  
  16.         static void Main(string[] args)
  17.         {
  18.             Console.Write("Read Num of digits:");
  19.             int num_of_dig = int.Parse(Console.ReadLine());
  20.             Console.WriteLine();
  21.             List<double> x = new List<double>();
  22.             List<double> F = new List<double>();
  23.             List<double> N = new List<double>();
  24.                    
  25.             double res = 0;
  26.             double[,] rr = new double[num_of_dig, num_of_dig];
  27.  
  28.             for (int i = 0; i < num_of_dig; i++)
  29.             {
  30.                 Console.Write("x{0}=", i);
  31.                 double iks = int.Parse(Console.ReadLine());
  32.                 x.Add(iks);
  33.                 F.Add(funct(iks));
  34.                 rr[i, 0] = funct(iks);
  35.             }
  36.             Console.Write("Please enter the x = ");
  37.             double ix = double.Parse(Console.ReadLine());
  38.             for (int i = 1; i < num_of_dig; i++)
  39.             {
  40.                 for (int j = 0; j < num_of_dig - i; j++)
  41.                 {
  42.                     rr[j, i] = (rr[j + 1, i - 1] - rr[j, i - 1]) / (x[i] - x[0]);
  43.                 }
  44.             }
  45.             for (int j = 0; j < num_of_dig; j++)
  46.             {
  47.                 double cmp = 1;
  48.                 for (int k = 0; k < num_of_dig - 1 - j; k++)
  49.                 {
  50.                     cmp *= (ix - x[k]);
  51.                 }
  52.                 res += cmp * rr[0, num_of_dig - 1 - j];
  53.             }
  54.             Console.WriteLine();
  55.             Console.WriteLine();
  56.             Console.Write("Result: {0}", res);
  57.             Console.WriteLine();
  58.             Console.WriteLine();
  59.         }
  60.     }
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement