示例#1
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()))
                           )
                       )
                   ));
        }
示例#2
0
 public static ValueTerm Apply(this FunctionTerm function, params ValueTerm[] parameters)
 {
     return(function.Apply((IEnumerable <ValueTerm>)parameters));
 }