Exemple #1
0
 public void MinBrent2()
 {
     double xmin = 0;
     //local minimum
     double realXmin = 4.057968;
     double eps = 1e-5;
     int maxCount = 50;
     LineSearch ls = new LineSearch();
     TestFunction1 f = new TestFunction1();
     int counter = ls.FindMinimumViaBrent(f,1,4,5,maxCount,eps,ref xmin);
     Assert.IsTrue(counter<maxCount);
     Assert.IsTrue (System.Math.Abs(xmin-realXmin)<eps);
 }
Exemple #2
0
 public void MinInterval3()
 {
     int maxCount=30;
     LineSearch ls = new LineSearch();
     TestFunction1 f = new TestFunction1();
     double[] res = new double[3];
     int counter = ls.FindMinInterval(f,4,2,maxCount, ref res);
     double aVal = f.GetVal(res[0]);
     double bVal = f.GetVal(res[1]);
     double cVal = f.GetVal(res[2]);
     Assert.IsTrue(counter<maxCount);
     Assert.IsTrue((aVal>bVal)&&(cVal>bVal));
 }
Exemple #3
0
 public void MinGold2()
 {
     double xmin=0;
     //local minimum
     double realXmin = 4.057968;
     double eps = 1e-5;
     int counterMax = 50;
     LineSearch ls = new LineSearch();
     TestFunction1 f = new TestFunction1();
     int counter = ls.FindMinimumViaGoldenSection(f,1,4,5,counterMax,eps,ref xmin);
     Assert.IsTrue(counter<counterMax);
     Assert.IsTrue (System.Math.Abs(xmin-realXmin)<eps);
 }
Exemple #4
0
        public void MinGold2()
        {
            double xmin = 0;
            //local minimum
            double        realXmin   = 4.057968;
            double        eps        = 1e-5;
            int           counterMax = 50;
            LineSearch    ls         = new LineSearch();
            TestFunction1 f          = new TestFunction1();
            int           counter    = ls.FindMinimumViaGoldenSection(f, 1, 4, 5, counterMax, eps, ref xmin);

            Assert.IsTrue(counter < counterMax);
            Assert.IsTrue(System.Math.Abs(xmin - realXmin) < eps);
        }
Exemple #5
0
 public void MinBrent1()
 {
     double xmin=0;
     int maxCount = 50;
     double realXmin = -1.364641;
     double eps = 1e-5;
     LineSearch ls = new LineSearch();
     TestFunction1 f = new TestFunction1();
     double[] res = new double[3];
     int counter = ls.FindMinInterval(f,-10,1,maxCount,ref res);
     counter = ls.FindMinimumViaBrent(f,res[0],res[1],res[2],maxCount,eps, ref xmin);
     Assert.IsTrue(counter<maxCount);
     Assert.IsTrue (System.Math.Abs(xmin-realXmin)<eps);
 }
Exemple #6
0
        public void MinBrent2()
        {
            double xmin = 0;
            //local minimum
            double        realXmin = 4.057968;
            double        eps      = 1e-5;
            int           maxCount = 50;
            LineSearch    ls       = new LineSearch();
            TestFunction1 f        = new TestFunction1();
            int           counter  = ls.FindMinimumViaBrent(f, 1, 4, 5, maxCount, eps, ref xmin);

            Assert.IsTrue(counter < maxCount);
            Assert.IsTrue(System.Math.Abs(xmin - realXmin) < eps);
        }
Exemple #7
0
 public void MinGold1()
 {
     double xmin=0;
     double realXmin = -1.364641;
     double eps = 1e-5;
     int counterMax = 50;
     LineSearch ls = new LineSearch();
     TestFunction1 f = new TestFunction1();
     double [] res = new double[3];
     int counter1 = ls.FindMinInterval(f,-10,1,30,ref res);
     int counter2 = ls.FindMinimumViaGoldenSection(f,res[0],res[1],res[2],counterMax,eps,ref xmin);
     Assert.IsTrue(counter2<counterMax);
     Assert.IsTrue (System.Math.Abs(xmin-realXmin)<eps);
 }
Exemple #8
0
        public void MinInterval3()
        {
            int           maxCount = 30;
            LineSearch    ls       = new LineSearch();
            TestFunction1 f        = new TestFunction1();

            double[] res     = new double[3];
            int      counter = ls.FindMinInterval(f, 4, 2, maxCount, ref res);
            double   aVal    = f.GetVal(res[0]);
            double   bVal    = f.GetVal(res[1]);
            double   cVal    = f.GetVal(res[2]);

            Assert.IsTrue(counter < maxCount);
            Assert.IsTrue((aVal > bVal) && (cVal > bVal));
        }
Exemple #9
0
        public void MinGold1()
        {
            double        xmin       = 0;
            double        realXmin   = -1.364641;
            double        eps        = 1e-5;
            int           counterMax = 50;
            LineSearch    ls         = new LineSearch();
            TestFunction1 f          = new TestFunction1();

            double [] res      = new double[3];
            int       counter1 = ls.FindMinInterval(f, -10, 1, 30, ref res);
            int       counter2 = ls.FindMinimumViaGoldenSection(f, res[0], res[1], res[2], counterMax, eps, ref xmin);

            Assert.IsTrue(counter2 < counterMax);
            Assert.IsTrue(System.Math.Abs(xmin - realXmin) < eps);
        }
Exemple #10
0
        public void MinBrent1()
        {
            double        xmin     = 0;
            int           maxCount = 50;
            double        realXmin = -1.364641;
            double        eps      = 1e-5;
            LineSearch    ls       = new LineSearch();
            TestFunction1 f        = new TestFunction1();

            double[] res     = new double[3];
            int      counter = ls.FindMinInterval(f, -10, 1, maxCount, ref res);

            counter = ls.FindMinimumViaBrent(f, res[0], res[1], res[2], maxCount, eps, ref xmin);
            Assert.IsTrue(counter < maxCount);
            Assert.IsTrue(System.Math.Abs(xmin - realXmin) < eps);
        }