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)); }
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())) ) ) )); }
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))); }
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))); }
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))); }
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)))); }
// 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))); }
public static ValueTerm ArcTangent(ValueTerm value) { if (value.Dimension != 1) { throw new ArgumentException("Dimension of 'value' is not 1."); } return(TermsWrapped.ArcTangent(value)); }
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)); }
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)); }
// 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)); }
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)); }
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)); }
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; }
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); } }
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()); }
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()); }
public static ValueTerm Tangent(ValueTerm value) { lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.Tangent(value.Value))); }
public static ValueTerm ArcCosine(ValueTerm value) { lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.ArcCosine(value.Value))); }
public static ValueTerm Transpose(ValueTerm value) { lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.Transpose(value.Value))); }
public static ValueTerm MatrixProduct(ValueTerm value1, ValueTerm value2) { lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.MatrixProduct(value1.Value, value2.Value))); }
public static ValueTerm Exponentiation(ValueTerm value1, ValueTerm value2) { lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.Exponentiation(value1.Value, value2.Value))); }
public static ValueTerm Selection(ValueTerm value, int index) { lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.Selection(value.Value, index))); }
public static ValueTerm Application(FunctionTerm function, ValueTerm value) { lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.Application(function.Function, value.Value))); }
public static void DisposeValue(ValueTerm value) { lock (GeneralNative.Synchronization) TermsNative.DisposeValue(value.Value); }
public static FunctionTerm Abstraction(ValueTerm variable, ValueTerm value) { lock (GeneralNative.Synchronization) return(new FunctionTerm(TermsNative.Abstraction(variable.Value, value.Value))); }
public static ValueTerm ValueSimplify(ValueTerm value) { lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.ValueSimplify(value.Value))); }
public static int ValueDimension(ValueTerm value) { lock (GeneralNative.Synchronization) return(TermsNative.ValueDimension(value.Value)); }
public static string ValueToString(ValueTerm value) { lock (GeneralNative.Synchronization) return(TermsNative.ValueToString(value.Value)); }
public static ValueTerm ArcTangent2(ValueTerm value1, ValueTerm value2) { lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.ArcTangent2(value1.Value, value2.Value))); }