Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Ednomernaminimizaciq
- {
- class Program
- {
- static double gradientF(double x)
- {
- return -(1.0 / 2.0) * ((-2 * x - 3) / Math.Pow((-(x * x) - 3 * x + 10), 2.0 / 3.0)) + (1.0 / 3.0) * ((2 * x + 8) / Math.Pow((-(x * x) - 8 * x + 25), 2.0 / 3.0));
- }
- static double Fx(double x)
- {
- return -Math.Pow(-x*x - 3*x + 10, 1.0/3.0) + Math.Pow(x * x + 8 * x + 25, 1.0 / 3.0) + 1;
- }
- static void Main(string[] args)
- {
- Console.Write("x0: ");
- double xk = double.Parse(Console.ReadLine());
- Console.Write("a: ");
- double a = double.Parse(Console.ReadLine());
- Console.Write("k_max: ");
- double k_max = double.Parse(Console.ReadLine());
- Console.Write("eps_x: ");
- double eps_x = double.Parse(Console.ReadLine());
- Console.Write("eps_fx: ");
- double eps_fx = double.Parse(Console.ReadLine());
- int k = 0;
- double Fk, Fk1;
- Fk = Fx(xk);
- double xk1 = xk + a * Fk;
- Fk1 = Fx(xk1);
- double gFk, gFk1;
- gFk = gradientF(xk);
- gFk1 = gradientF(xk1);
- double min = Fk;
- while (k <= k_max && Math.Abs(xk - xk1) > eps_x && Math.Abs(gFk1 - gFk) > eps_fx)
- {
- xk = xk1;
- Fk = Fx(xk);
- min = Math.Min(min, Fk);
- gFk = gradientF(xk);
- gFk1 = gradientF(xk1);
- xk1 = xk + a * Fk;
- Fk1 = Fx(xk1);
- k++;
- }
- Console.WriteLine($"xk = {xk}");
- Console.WriteLine($"k = {k}");
- Console.WriteLine($"min = {min}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement