Example #1
0
        public static RationalFunction ConvertToRationalFunction(this alglib.barycentricinterpolant function)
        {
            if (function == null)
            {
                throw new ArgumentNullException();
            }

            var n = function.innerobj.n;

            if (n <= 2)
            {
                // linear function, let's convert it to that form for simplicity
                double[] coefficients;
                alglib.polynomialbar2pow(function, out coefficients);

                return(RationalFunction.BuildPolynomial(coefficients.Select(x => (float)x).ToArray()));
            }
            else
            {
                // maintain barycentric representation
                var w = ConvertToFloatArray(function.innerobj.w, n);
                var x = ConvertToFloatArray(function.innerobj.x, n);
                var y = ConvertToFloatArray(function.innerobj.y, n);

                return(RationalFunction.BuildBarycentric(w, x, y, (float)function.innerobj.sy));
            }
        }
Example #2
0
        public static RationalFunction BuildPolynomial(params float[] coefficients)
        {
            if (coefficients == null)
            {
                throw new ArgumentNullException();
            }
            if (coefficients.Length > MaxOrder)
            {
                throw new ArgumentException("Maximum supported order exceeded.");
            }

            var result = new RationalFunction();

            result.FunctionForm = RationalFunctionForm.PolynomialForm;
            result.Order        = (ushort)coefficients.Length;
            result.W            = new float[MaxOrder];
            coefficients.CopyTo(result.W, 0);
            result.SY = 1.0f;

            return(result);
        }
Example #3
0
        public static RationalFunction BuildBarycentric(float[] w, float[] x, float[] y, float sy)
        {
            if (w == null || x == null || y == null)
            {
                throw new ArgumentNullException();
            }
            if (w.Length != x.Length || x.Length != y.Length)
            {
                throw new ArgumentException("Mismatched array lengths.");
            }
            if (!IsSorted(x))
            {
                throw new ArgumentException("Points are not sorted by x coordinate.");
            }
            if (!w.All(wi => Math.Abs(wi) <= 1))
            {
                throw new ArgumentException("Weight values are not normalized to -1 to 1 range.");
            }
            if (!y.All(yi => Math.Abs(yi) <= 1))
            {
                throw new ArgumentException("Y values are not normalized to -1 to 1 range.");
            }

            var result = new RationalFunction();

            result.FunctionForm = RationalFunctionForm.BarycentricForm;
            result.Order        = (ushort)w.Length;
            result.W            = new float[MaxOrder];
            w.CopyTo(result.W, 0);
            result.X = new float[MaxOrder];
            x.CopyTo(result.X, 0);
            result.Y = new float[MaxOrder];
            y.CopyTo(result.Y, 0);
            result.SY = sy;

            return(result);
        }