public static Func <Fraction, V> Interpolate <V>(this IVectorSpace <Fraction, V> space, V start, V end) { return(scale => { return space.Add(space.Scale(scale.Complement(), start), space.Scale(scale, end)); }); }
public static IVectorSpace <S, IPoint <V> > Geometry <S, V>(this IVectorSpace <S, V> space) { return(new VectorSpace <S, IPoint <V> >( zero: new Point <V>(axis => space.Zero), addF: (left, right) => { return new Point <V>(axis => space.Add(left.On(axis), right.On(axis))); }, scaleF: (scale, point) => { return new Point <V>(axis => space.Scale(scale, point.On(axis))); })); }
/// <summary> /// Obtém uma base ortogonalizada a partir da base actual. /// </summary> /// <param name="coefficientsField">O corpo responsável pelas operações sobre os coeficientes.</param> /// <param name="vectorSpace">O espaço responsável pela multiplicação de um escalar com um vector.</param> /// <param name="scalarProduct">O produto escalar.</param> /// <returns>A base ortogonalizada.</returns> /// <exception cref="ArgumentNullException">Se algum dos argumentos for nulo.</exception> public VectorSpaceGenerator <CoeffType> GetOrthogonalizedBase( IField <CoeffType> coefficientsField, IVectorSpace <CoeffType, IMathVector <CoeffType> > vectorSpace, IScalarProductSpace <IMathVector <CoeffType>, CoeffType> scalarProduct) { if (coefficientsField == null) { throw new ArgumentNullException("coefficientsField"); } else if (vectorSpace == null) { throw new ArgumentNullException("vectorSpace"); } else if (scalarProduct == null) { throw new ArgumentNullException("scalarProduct"); } else { var result = new List <IMathVector <CoeffType> >(); // Mantém a lista de resultados intermédios var intermediaryResults = new List <CoeffType>(); if (this.basisVectors.Count > 0) { var basisCount = this.basisVectors.Count; var i = -1; var control = 0; while (control < basisCount) { var currentVector = this.basisVectors[control]; if (!currentVector.IsNull(coefficientsField)) { i = control; control = basisCount; } else { ++control; } } if (i != -1) { --basisCount; var currentVector = this.basisVectors[i]; result.Add(currentVector); if (i < basisCount) { var denom = scalarProduct.Multiply(currentVector, currentVector); intermediaryResults.Add(denom); ++i; for (; i < basisCount; ++i) { currentVector = this.basisVectors[i]; for (int j = 0; j < result.Count; ++j) { denom = intermediaryResults[j]; if (!coefficientsField.IsAdditiveUnity(denom)) { var orthoVector = result[j]; var num = scalarProduct.Multiply(currentVector, orthoVector); if (!coefficientsField.IsAdditiveUnity(num)) { var scalar = coefficientsField.Multiply( num, coefficientsField.MultiplicativeInverse(denom)); scalar = coefficientsField.AdditiveInverse(scalar); if (!coefficientsField.IsMultiplicativeUnity(scalar)) { orthoVector = vectorSpace.MultiplyScalar(scalar, orthoVector); currentVector = vectorSpace.Add(currentVector, orthoVector); } } } } // Já foi calculado o vector ortogonal denom = scalarProduct.Multiply(currentVector, currentVector); if (coefficientsField.IsAdditiveUnity(denom)) { if (!currentVector.IsNull(coefficientsField)) { intermediaryResults.Add(denom); result.Add(currentVector); } } else { intermediaryResults.Add(denom); result.Add(currentVector); } } // Na útlima iteração não é necessário calcular o produto escalar currentVector = this.basisVectors[i]; for (int j = 0; j < result.Count; ++j) { denom = intermediaryResults[j]; if (!coefficientsField.IsAdditiveUnity(denom)) { var orthoVector = result[j]; var num = scalarProduct.Multiply(currentVector, orthoVector); if (!coefficientsField.IsAdditiveUnity(num)) { var scalar = coefficientsField.Multiply( num, coefficientsField.MultiplicativeInverse(denom)); scalar = coefficientsField.AdditiveInverse(scalar); if (!coefficientsField.IsMultiplicativeUnity(scalar)) { orthoVector = vectorSpace.MultiplyScalar(scalar, orthoVector); currentVector = vectorSpace.Add(currentVector, orthoVector); } } } } // Já foi calculado o vector ortogonal if (!currentVector.IsNull(coefficientsField)) { result.Add(currentVector); } } } } return(new VectorSpaceGenerator <CoeffType>( this.vectorSpaceDimension, result)); } }