Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Gradient
  8. {
  9. class Program
  10. {
  11. static Func<double,double> fx = x => Math.Sqrt(5 * x * x + x + 6) + Math.Sqrt(3 * x + 7);
  12. static Func<double,double> grad = x => ((10 * x) / (2 * Math.Sqrt(5 * x * x + x + 6))) + 3 / (2 * Math.Sqrt(3 * x + 7));
  13. static double xOld = 0;
  14. static double xNew;
  15. static int kmax = 25000;
  16. static int k = 1;
  17. static double A = 0.2;
  18. static double eps = 0.3;
  19. static double S = double.MaxValue;
  20.  
  21. static void Main(string[] args)
  22. {
  23. while (k < kmax && eps < S)
  24. {
  25. xNew = xOld - A * grad(xOld);
  26. S = Math.Abs(xNew - xOld);
  27. xOld = xNew;
  28. k++;
  29. }
  30.  
  31. Console.WriteLine($"x = {0}", xOld);
  32. Console.WriteLine($"f(x) = {0}", fx(xOld));
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement