Advertisement
Guest User

Untitled

a guest
Nov 9th, 2021
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.62 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp6
  4. {
  5.     class Program
  6.     {              
  7.         static double foo(double x)
  8.         {
  9.             return x * x - 2*x - 2* Math.Cos(x);
  10.         }
  11.         static void Main(string[] args)
  12.         {
  13.             double masheps = 1;
  14.             while (1 + masheps > 1)
  15.                 masheps = masheps / 2;
  16.             double a = -0.5;
  17.             double b = 1;
  18.             double L = a+b;
  19.             //=================================================================
  20.             // Шаг 2
  21.             double x0 = 1 / (2 * L) * (foo(a) - foo(b) + L);
  22.             double y0 = 1 / 2 * (foo(a) - foo(b) + (a-b));
  23.             double phimin = y0;
  24.             // Шаг 3
  25.             double delta = 1 / (2 * L) * (foo(x0) - phimin);
  26.          
  27.             // Шаг 4
  28.  
  29.            
  30.                 if (2 * (b-a)* delta < masheps)
  31.                 {
  32.                     Console.WriteLine(delta);
  33.                     Console.WriteLine(x0);
  34.                    
  35.                 }
  36.  
  37.             //шаг 5
  38.             double x1L = x0 - delta;
  39.             double x1R = x0 + delta;
  40.             double phi = 1 / 2 * (foo(x0) + phimin);
  41.             //шаг 6
  42.             if (foo(x1L) < foo(x1R))
  43.                 {
  44.                     x0 = x1L;
  45.                 Console.WriteLine(x0);
  46.                 Console.WriteLine("x1l");
  47.             }
  48.                 else
  49.                 {
  50.                     x0 = x1R;
  51.                 Console.WriteLine(x0);
  52.                 Console.WriteLine("x1r");
  53.             }
  54.                 y0 = phi;
  55.      
  56.             Console.ReadKey();
  57.  
  58.         }
  59.     }
  60. }
  61.  
  62.  
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement