Example #1
0
        private Math_Collection.LinearAlgebra.Vectors.Vector GetCoefficientVector(double[] gi)
        {
            Math_Collection.LinearAlgebra.Vectors.Vector v = new Math_Collection.LinearAlgebra.Vectors.Vector(new double[_amountOfSplineParts + 1]);
            for (int i = 2; i <= _amountOfSplineParts; i++)
            {
                v[i - 1] = gi[i];
            }

            return(v);
        }
Example #2
0
        private List <double> CalculateD(Math_Collection.LinearAlgebra.Vectors.Vector outcome, List <double> hList)
        {
            List <double> dList = new List <double>();

            for (int i = 0; i < outcome.Size - 1; i++)
            {
                dList.Add((outcome[i + 1] - outcome[i]) / (3 * hList[i]));
            }

            return(dList);
        }
Example #3
0
        private List <string> CreateSplineFunctions(List <double> bList, Math_Collection.LinearAlgebra.Vectors.Vector c, List <double> dList)
        {
            List <string> splineFunctionList = new List <string>();

            for (int i = 1; i < pointList.Count; i++)
            {
                splineFunctionList.Add("" + pointList[i - 1].Y +
                                       (bList[i - 1] < 0 ? "+(" : "+(") + bList[i - 1] + (c[i - 1] < 0 ? "*x)+(" : "*x)+(") +
                                       c[i - 1] + (dList[i - 1] < 0 ? "*(x^2))+(" : "*(x^2))+(") + dList[i - 1] + "*(x^3))");
            }
            return(splineFunctionList);
        }
Example #4
0
        private List <double> CalculateB(Math_Collection.LinearAlgebra.Vectors.Vector c, List <double> hList)
        {
            List <double> bList = new List <double>();

            for (int i = 1; i < pointList.Count; i++)
            {
                double b = ((pointList[i].Y - pointList[i - 1].Y) / hList[i - 1])
                           - ((hList[i - 1] / 3) * ((2 * c[i - 1]) + c[i]));
                bList.Add(b);
            }
            return(bList);
        }
Example #5
0
        private void Plot()
        {
            //Make asynchronous
            List <double> hList = CalculateH();
            List <double> gList = CalculateG(hList);

            Math_Collection.LinearAlgebra.Matrices.Matrix m = CreateSplineMatrix(hList);

            double[] gListAsArray = gList.ToArray();
            LGS      lgs          = new LGS(m, new Math_Collection.LinearAlgebra.Vectors.Vector(gListAsArray));

            //Make asynchronous
            Math_Collection.LinearAlgebra.Vectors.Vector outcome = lgs.Solve(LGS.SolveAlgorithm.Gauß);

            string sOutcome = outcome.ToString();

            List <double> bList = CalculateB(outcome, hList);
            List <double> dList = CalculateD(outcome, hList);

            SolveSplineFunctions(CreateSplineFunctions(bList, outcome, dList));
        }
Example #6
0
        private Math_Collection.LinearAlgebra.Vectors.Vector CopyTo(Math_Collection.LinearAlgebra.Vectors.Vector v, int startIndex, int sizeForNewArray)
        {
            if (v == null)
            {
                return(null);
            }

            if (v.Size == 0)
            {
                return(v);
            }

            if (sizeForNewArray < v.Size + startIndex)
            {
                throw new System.ArgumentException("The new vector must be big enough to old the data from the old vector");
            }

            double[] newValues = new double[sizeForNewArray];
            v.Values.CopyTo(newValues, startIndex);

            return(new Math_Collection.LinearAlgebra.Vectors.Vector(newValues));
        }
Example #7
0
        /// <summary>
        /// Calculates all polynominal parts of the spline
        /// </summary>
        /// <returns>A List of Functions that represents all polynominals</returns>
        /// <seealso cref="http://www.tm-mathe.de/Themen/html/funnatsplines.html"/>
        private List <Function> CalculateSplineParts()
        {
            if (_sourcePoints != null && _sourcePoints.Count < 3)
            {
                return(null);
            }

            // 3.Degree Polynomial := f(x) = a + bx + cx^2 + dx^3
            // f'(x) = b + 2cx + 3dx^2
            // f''(x) = 2c + 6dx

            Parser parser = new Parser();

            double[] xs = _sourcePoints.Keys.ToArray();
            double[] ys = _sourcePoints.Values.ToArray();

            #region Calculate Help Variable hi and gi

            double[] hi = CalculateH(xs);

            double[] gi = CalcualteG(ys, hi);

            #endregion

            #region Calculate all c's

            Matrix coefficientMatrix = GetCoefficientMatrix(hi);
            Math_Collection.LinearAlgebra.Vectors.Vector coefficientVector = GetCoefficientVector(gi);
            LGS lgs = new LGS(coefficientMatrix, coefficientVector);

            Math_Collection.LinearAlgebra.Vectors.Vector resultFromLGS = lgs.Solve(Math_Collection.Enums.ESolveAlgorithm.eGaussianElimination);

            double[] ci = new double[_amountOfSplineParts + 2];
            for (int i = 2; i <= _amountOfSplineParts + 1; i++)
            {
                ci[i] = resultFromLGS[i - 1];
            }

            #endregion

            #region Calculates all a values

            // a's = yi-1
            double[] ai = new double[_amountOfSplineParts + 1];
            for (int i = 1; i <= _amountOfSplineParts; i++)
            {
                ai[i] = ys[i - 1];
            }

            #endregion

            #region Calculate all b's

            // bi = (yi - yi-1) / hi - (hi / 3) * (2*ci + ci+1)

            double[] bi = new double[_amountOfSplineParts + 1];
            for (int i = 1; i <= _amountOfSplineParts; i++)
            {
                bi[i] = ((ys[i] - ys[i - 1]) / hi[i]) - (hi[i] / 3) * (2 * ci[i] + ci[i + 1]);
            }

            #endregion

            #region Calculate all d's

            // di = (ci+1 - ci) / 3 * hi

            double[] di = new double[_amountOfSplineParts + 1];
            for (int i = 1; i <= _amountOfSplineParts; i++)
            {
                di[i] = (ci[i + 1] - ci[i]) / (3 * hi[i]);
            }

            #endregion

            #region Generate all Functions

            Function[] functionParts = new Function[_amountOfSplineParts];
            for (int i = 1; i <= _amountOfSplineParts; i++)
            {
                string f = ai[i] + "+" + bi[i] + "*x+" + ci[i] + "*x^2+" + di[i] + "*x^3";
                functionParts[i - 1] = parser.ParseFunction(f);
            }

            #endregion

            return(functionParts.ToList());
        }