chillurbrain

Untitled

Sep 22nd, 2015
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. //Метод би-секции
  2. using System;
  3.  
  4. namespace ConsoleApplication2
  5. {
  6.     class Program
  7.     {
  8.         static double f(double x)
  9.         {
  10.             x = Math.Pow(x, 4) - 8 * Math.Pow(x, 3) - (2 * x * x) - 3;
  11.             return x;
  12.         }
  13.         static void Main(string[] args)
  14.         {
  15.             double a, b, c = 0.0, eps;
  16.  
  17.             Console.Write("Введите a: ");
  18.             a = Convert.ToDouble(Console.ReadLine());
  19.  
  20.             Console.Write("Введите b: ");
  21.             b = Convert.ToDouble(Console.ReadLine());
  22.  
  23.             Console.Write("Введите eps: ");
  24.             eps = Convert.ToDouble(Console.ReadLine());
  25.  
  26.             do
  27.             {
  28.                 c = (a + b) / 2;
  29.                 if ((f(a) * f(c)) > 0)
  30.                     a = c;
  31.                 else
  32.                     b = c;
  33.             }
  34.             while ((b-a) > 2 * eps);
  35.  
  36.             c = (a + b) / 2;
  37.  
  38.             Console.Write("Корень: ");
  39.             Console.WriteLine(c);
  40.  
  41.             Console.ReadKey();
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment