[Рефераты, сочинения, доклады, презентации ]

public class Gradient

    {

        public List<double[]> x { get; set; }

        public double alpha;

        public double betta;

        public double delta;

        public double eps { get; set; }

        public double FOpt { get; set; }

        public List<double[]> p { get; set; }

        public BigFunction F { get; set; }

        public BigFunction[] derFs { get; set; }

        public double[] derF{ get; set; }

 

        public double Norm (double[] a)

        {

            double norm = 0;

            for (int i = 0; i < a.Length; i++) norm += Math.Abs(a[i]);

            return norm;

        }

        public double[] GradientFunc()

        {

            betta = 0.5;

            int k =0;

            derF = new double[derFs.Length];

            double normo4ka;

            p = new List<double[]>();

            do

            {

                for (int i = 0; i < derF.Length; i++) derF[i] = derFs[i](x[k]);

                normo4ka = Norm(derF);

                p.Add(Ext.ScalarMultiplay(derF, -1f));

                if (normo4ka <= eps) break;

                alpha = 1;

                do

                {

                    delta = F(Ext.Plus(x[k], Ext.ScalarMultiplay(p[k], alpha))) - F(x[k]) + (alpha / 2) * (normo4ka * normo4ka);

                    if (delta >= 0) alpha *= betta;

                }

                while (delta >= 0);

                x.Add(Ext.Plus(x[k], Ext.ScalarMultiplay(p[k], alpha)));

                k++;

            }

            while(normo4ka > eps);

            FOpt = F(x[k]);

            return x[k];

        }    }