Advertisement
slik1977

Main_1_2

Mar 17th, 2022
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. class Program
  5. {
  6.     public static readonly Func<double, double> Function1 = x
  7.         => 3 * Math.Pow(x, 4) + Math.Pow(x - 1, 2);
  8.     public static readonly Func<double, double> Function2 = x
  9.         => Math.Pow(x, 3) * Math.Sin(x);
  10.  
  11.     public static void Main()
  12.     {
  13.         // double.TryParse(Console.ReadLine(), out double a);
  14.         // double.TryParse(Console.ReadLine(), out double b);
  15.         Console.WriteLine("***Dichotomy method***\n");
  16.         (double end, double start) interval = new DichotomyMethod().FindRoot(Function2, 0, 6);
  17.         var x = (interval.start + interval.end) / 2;
  18.  
  19.         Console.WriteLine($"Interval: {interval}");
  20.         Console.WriteLine($"Root: {x}");
  21.         Console.WriteLine($"Value in root: {Function2(x)}");
  22.  
  23.         Console.WriteLine("\n\n***Golden section method***\n");
  24.         var goldenSectionMethod = new GoldenSectionMethod(Function2);
  25.         var y = goldenSectionMethod.FindMin(0, 6);
  26.         Console.WriteLine("Root: " + y);
  27.         Console.WriteLine($"Value in root: {Function2(y)}");
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement