예제 #1
0
        public static FunctionTerm Polynomial(IEnumerable <FunctionTerm> basis, int dimension)
        {
            if (basis == null)
            {
                throw new ArgumentNullException("basis");
            }
            if (dimension < 0)
            {
                throw new ArgumentOutOfRangeException("dimension");
            }

            ValueTerm variable = Variable("x");
            IEnumerable <ValueTerm> coefficients =
                (
                    from index in Enumerable.Range(0, basis.Count())
                    select Variable(string.Format("c_{0}", index), dimension)
                )
                .ToArray();
            IEnumerable <ValueTerm> parameters = Enumerables.Concatenate(Enumerables.Create(variable), coefficients);

            if (!basis.Any())
            {
                return(Constant(Enumerable.Repeat(0.0, dimension)).Abstract(parameters));
            }

            IEnumerable <ValueTerm> basisValues = basis.Select(basisFunction => basisFunction.Apply(variable));

            return(Sum(Enumerable.Zip(basisValues, coefficients, Scaling)).Abstract(parameters));
        }
예제 #2
0
        public static ValueTerm IntegrateTrapezoid(FunctionTerm function, OrderedRange <double> bounds, int segmentCount)
        {
            if (segmentCount < 1)
            {
                throw new ArgumentOutOfRangeException("segmentCount");
            }

            ValueTerm segmentWidth = Terms.Constant(bounds.Length() / segmentCount);

            IEnumerable <ValueTerm> values =
                (
                    from segmentPosition in Scalars.GetIntermediateValuesSymmetric(bounds.Start, bounds.End, segmentCount)
                    select function.Apply(Terms.Constant(segmentPosition))
                )
                .ToArray();

            return(Terms.Product
                   (
                       segmentWidth,
                       Terms.Sum
                       (
                           Enumerables.Concatenate
                           (
                               Enumerables.Create(Terms.Product(Terms.Constant(0.5), values.First())),
                               values.Skip(1).SkipLast(1),
                               Enumerables.Create(Terms.Product(Terms.Constant(0.5), values.Last()))
                           )
                       )
                   ));
        }
예제 #3
0
        public static ValueTerm Normal(ValueTerm value)
        {
            if (value.Dimension != 2)
            {
                throw new ArgumentException("Dimension of 'value' is not 2.");
            }

            return(Vector(Negate(value.Select(1)), value.Select(0)));
        }
예제 #4
0
        public static ValueTerm Direction(ValueTerm value)
        {
            if (value.Dimension != 1)
            {
                throw new ArgumentException("Dimension of 'value' is not 1.");
            }

            return(Vector(Cosine(value), Sine(value)));
        }
예제 #5
0
        public static ValueTerm Angle(ValueTerm value)
        {
            if (value.Dimension != 2)
            {
                throw new ArgumentException("Dimension of 'value' is not 2.");
            }

            return(TermsWrapped.ArcTangent2(value.Select(1), value.Select(0)));
        }
예제 #6
0
        public static ValueTerm PolarToCartesian(ValueTerm value)
        {
            if (value.Dimension != 2)
            {
                throw new ArgumentException("Dimension of 'value' is not 2.");
            }

            return(Scaling(value.Select(0), Direction(value.Select(1))));
        }
예제 #7
0
        // polar coordinates
        public static ValueTerm CartesianToPolar(ValueTerm value)
        {
            if (value.Dimension != 2)
            {
                throw new ArgumentException("Dimension of 'value' is not 2.");
            }

            return(Vector(Norm(value), Angle(value)));
        }
예제 #8
0
        public static ValueTerm ArcTangent(ValueTerm value)
        {
            if (value.Dimension != 1)
            {
                throw new ArgumentException("Dimension of 'value' is not 1.");
            }

            return(TermsWrapped.ArcTangent(value));
        }
예제 #9
0
        public static ValueTerm Scaling(ValueTerm factor, ValueTerm value)
        {
            if (factor.Dimension != 1)
            {
                throw new ArgumentException("Dimension of 'factor' is not 1.");
            }

            return(TermsWrapped.Product(factor, value));
        }
예제 #10
0
        public static ValueTerm DotProduct(ValueTerm value1, ValueTerm value2)
        {
            if (value1.Dimension != value2.Dimension)
            {
                throw new ArgumentException("Dimensions of 'value1' and 'value2' do not match.");
            }

            return(TermsWrapped.MatrixProduct(TermsWrapped.Transpose(value1), value2));
        }
예제 #11
0
        // common operations
        public static ValueTerm Sum(ValueTerm value1, ValueTerm value2)
        {
            if (value1.Dimension != value2.Dimension)
            {
                throw new ArgumentException("Dimensions of 'value1' and 'value2' do not match.");
            }

            return(TermsWrapped.Sum(value1, value2));
        }
예제 #12
0
        public static ValueTerm Product(ValueTerm value1, ValueTerm value2)
        {
            if (value1.Dimension != 1)
            {
                throw new ArgumentException("Dimension of 'value1' is not 1.");
            }
            if (value2.Dimension != 1)
            {
                throw new ArgumentException("Dimension of 'value2' is not 1.");
            }

            return(TermsWrapped.Product(value1, value2));
        }
예제 #13
0
        public static ValueTerm Exponentiation(ValueTerm @base, ValueTerm exponent)
        {
            if (@base.Dimension != 1)
            {
                throw new ArgumentException("Dimension of 'base' is not 1.");
            }
            if (exponent.Dimension != 1)
            {
                throw new ArgumentException("Dimension of 'exponent' is not 1.");
            }

            return(TermsWrapped.Exponentiation(@base, exponent));
        }
예제 #14
0
        public Substitution(ValueTerm variable, ValueTerm value)
        {
            if (variable == null)
            {
                throw new ArgumentNullException("variable");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            this.variable = variable;
            this.value    = value;
        }
예제 #15
0
        public static IEnumerable <double> ValueEvaluate(ValueTerm value)
        {
            lock (GeneralNative.Synchronization)
            {
                IntPtr values = Enumerable.Repeat(0.0, value.Dimension).Copy();

                TermsNative.ValueEvaluate(value.Value, values);

                IEnumerable <double> result = values.Read <double>(value.Dimension);

                Marshal.FreeCoTaskMem(values);

                return(result);
            }
        }
예제 #16
0
        public static IEnumerable <FunctionTerm> StandardPolynomialBasis(int length)
        {
            if (length < 0)
            {
                throw new ArgumentOutOfRangeException("length");
            }

            ValueTerm variable = Variable("x");

            return
                ((
                     from index in Enumerable.Range(0, length)
                     select Exponentiation(variable, Constant(index)).Abstract(variable)
                     )
                 .ToArray());
        }
예제 #17
0
        public static IEnumerable <FunctionTerm> BernsteinPolynomialBasis(int length)
        {
            if (length < 0)
            {
                throw new ArgumentOutOfRangeException("length");
            }

            ValueTerm variable = Variable("x");

            int degree = length - 1;

            return
                ((
                     from index in Enumerable.Range(0, length)
                     select Product
                     (
                         Constant(Scalars.BinomialCoefficient(degree, index)),
                         Exponentiation(variable, Constant(index)),
                         Exponentiation(Difference(Constant(1), variable), Constant(degree - index))
                     )
                     .Abstract(variable)
                     )
                 .ToArray());
        }
예제 #18
0
 public static ValueTerm Tangent(ValueTerm value)
 {
     lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.Tangent(value.Value)));
 }
예제 #19
0
 public static ValueTerm ArcCosine(ValueTerm value)
 {
     lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.ArcCosine(value.Value)));
 }
예제 #20
0
 public static ValueTerm Transpose(ValueTerm value)
 {
     lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.Transpose(value.Value)));
 }
예제 #21
0
 public static ValueTerm MatrixProduct(ValueTerm value1, ValueTerm value2)
 {
     lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.MatrixProduct(value1.Value, value2.Value)));
 }
예제 #22
0
 public static ValueTerm Exponentiation(ValueTerm value1, ValueTerm value2)
 {
     lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.Exponentiation(value1.Value, value2.Value)));
 }
예제 #23
0
 public static ValueTerm Selection(ValueTerm value, int index)
 {
     lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.Selection(value.Value, index)));
 }
예제 #24
0
 public static ValueTerm Application(FunctionTerm function, ValueTerm value)
 {
     lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.Application(function.Function, value.Value)));
 }
예제 #25
0
 public static void DisposeValue(ValueTerm value)
 {
     lock (GeneralNative.Synchronization) TermsNative.DisposeValue(value.Value);
 }
예제 #26
0
 public static FunctionTerm Abstraction(ValueTerm variable, ValueTerm value)
 {
     lock (GeneralNative.Synchronization) return(new FunctionTerm(TermsNative.Abstraction(variable.Value, value.Value)));
 }
예제 #27
0
 public static ValueTerm ValueSimplify(ValueTerm value)
 {
     lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.ValueSimplify(value.Value)));
 }
예제 #28
0
 public static int ValueDimension(ValueTerm value)
 {
     lock (GeneralNative.Synchronization) return(TermsNative.ValueDimension(value.Value));
 }
예제 #29
0
 public static string ValueToString(ValueTerm value)
 {
     lock (GeneralNative.Synchronization) return(TermsNative.ValueToString(value.Value));
 }
예제 #30
0
 public static ValueTerm ArcTangent2(ValueTerm value1, ValueTerm value2)
 {
     lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.ArcTangent2(value1.Value, value2.Value)));
 }