Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Gradient
- {
- class Program
- {
- static Func<double,double> fx = x => Math.Sqrt(5 * x * x + x + 6) + Math.Sqrt(3 * x + 7);
- static Func<double,double> grad = x => ((10 * x) / (2 * Math.Sqrt(5 * x * x + x + 6))) + 3 / (2 * Math.Sqrt(3 * x + 7));
- static double xOld = 0;
- static double xNew;
- static int kmax = 25000;
- static int k = 1;
- static double A = 0.2;
- static double eps = 0.3;
- static double S = double.MaxValue;
- static void Main(string[] args)
- {
- while (k < kmax && eps < S)
- {
- xNew = xOld - A * grad(xOld);
- S = Math.Abs(xNew - xOld);
- xOld = xNew;
- k++;
- }
- Console.WriteLine($"x = {0}", xOld);
- Console.WriteLine($"f(x) = {0}", fx(xOld));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement