public void CalculateParametersTest()
        {
            LeastSquares target = new QuadraticFit();

            //Excel generated data, y = 5 -7x +2xx
            target.Points.Add(new DPoint(0, 5));
            target.Points.Add(new DPoint(1, 0));
            target.Points.Add(new DPoint(2, -1));
            target.Points.Add(new DPoint(3, 2));
            target.Points.Add(new DPoint(4, 9));
            target.Points.Add(new DPoint(5, 20));

            Matrix expected = new Matrix(new double[, ] {
                { 5 },
                { -7 },
                { 2 }
            });
            Matrix actual;

            actual = target.CalculateParameters();
            actual.FactorInScalar();
            //			Debug.WriteLine(actual.ToString());
            //			Debug.WriteLine(expected.ToString());
            //have to string compare due to double precision
            Assert.AreEqual(expected.ToString(), actual.ToString());
        }
        public void CoefficientOfDeterminationTest()
        {
            LeastSquares target = new QuadraticFit();

            target.Points.AddRange(testData1());
            Matrix coeff = target.CalculateParameters();

            Assert.AreEqual(4.1, target.MeanYValue());
            Assert.AreEqual("0.9564", target.CoefficientOfDetermination().ToString("0.0000"));
        }
        public void CalculateParametersTest3()
        {
            LeastSquares target = new QuadraticFit();

            target.Points.AddRange(testData1());
            Matrix coeff = target.CalculateParameters();

            Assert.AreEqual("1.0909", coeff[0, 0].ToString("0.0000"));
            Assert.AreEqual("2.8758", coeff[1, 0].ToString("0.0000"));
            Assert.AreEqual("-0.3485", coeff[2, 0].ToString("0.0000"));
        }
        public void CalculateTest()
        {
            //Excel generated data, y = 5 -7x +2xx
            QuadraticFit target = new QuadraticFit();             // TODO: Initialize to an appropriate value

            target.Points.Add(new DPoint(0, 5));
            target.Points.Add(new DPoint(1, 0));
            target.Points.Add(new DPoint(2, -1));
            target.Points.Add(new DPoint(3, 2));
            target.Points.Add(new DPoint(4, 9));
            target.Points.Add(new DPoint(5, 20));
            target.CalculateParameters();

            Assert.AreEqual(3239, target.Calculate(42));
        }
        public void ParametersTest()
        {
            QuadraticFit target = new QuadraticFit();

            target.Points.AddRange(realData());
            Matrix parameters = target.CalculateParameters();

            Debug.WriteLine(parameters.ToString());
            /// Exel gives the following formula:
            /// y = -2E-05x2 + 1.0171x - 0.1298
            //Constant term
            Assert.AreEqual("-0.1298", parameters[0, 0].ToString("0.0000"));
            //x term
            Assert.AreEqual("1.0171", parameters[1, 0].ToString("0.0000"));
            //x squared term
            Assert.AreEqual("-0.00002", parameters[2, 0].ToString("0.00000"));
        }
        public void CalculateParametersTest2()
        {
            LeastSquares target = new QuadraticFit();

            target.Points.Add(new DPoint(2, 4));
            target.Points.Add(new DPoint(4, 16));
            target.Points.Add(new DPoint(5, 25));

            Matrix expected = new Matrix(new double[, ] {
                { 0 },
                { 0 },
                { 1 }
            });
            Matrix actual;

            actual = target.CalculateParameters();
            actual.FactorInScalar();
            //			Debug.WriteLine(actual.ToString());
            //			Debug.WriteLine(expected.ToString());
            //have to string compare due to double precision
            Assert.AreEqual(expected.ToString(), actual.ToString());
        }