コード例 #1
0
        public void SolveLinearFunctionViaInterface()
        {
            List <double> x;
            List <double> y;

            ConvertXYDataToArrays(CalculateLine(), out x, out y);

            var regression = new AlglibRegression();


            var coeffs = new double[2];

            //initial conditions
            coeffs[0] = 2;
            coeffs[1] = 2;
            var worked = regression.Fit(x, y, BasisFunctionsEnum.Linear, ref coeffs);

            Assert.AreEqual(5, coeffs[0], .0001);
            Assert.AreEqual(0, coeffs[1], .0001);

            Assert.AreEqual(true, worked.DidConverge);
        }
コード例 #2
0
        public void SolveQuadraticFunctionViaInterface()
        {
            List <double> x;
            List <double> y;

            ConvertXYDataToArrays(CalculatedParabola(), out x, out y);

            var regression = new AlglibRegression();
            var coeffs     = new double[3];

            //initial conditions
            coeffs[0] = 1;
            coeffs[1] = 1;
            coeffs[2] = 1;
            var worked = regression.Fit(x, y, BasisFunctionsEnum.PolynomialQuadratic, ref coeffs);

            Assert.AreEqual(-0.99999999960388553d, coeffs[0], .000001);
            Assert.AreEqual(2.410211171560969E-10d, coeffs[1], .000001);
            Assert.AreEqual(99.999999976322613d, coeffs[2], .000001);

            Assert.AreEqual(true, worked.DidConverge);
        }