chillurbrain

Untitled

Sep 22nd, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 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, c0 = 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.                 c0 = c;
  29.                 c = a - (b - a) / (f(b) - f(a)) * f(a);
  30.                 if ((f(a) * f(c)) > 0)
  31.                     a = c;
  32.                 else
  33.                     b = c;
  34.             }
  35.             while (Math.Abs(c - c0) > eps);
  36.  
  37.             Console.Write("Корень: ");
  38.             Console.WriteLine(c);
  39.  
  40.             Console.ReadKey();
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment