/** Find the orthogonal projection of this vector onto another vector. * @param v vector onto which {@code this} must be projected * @return projection of {@code this} onto {@code v} * @throws DimensionMismatchException if {@code v} is not the same size as * {@code this} * @throws MathArithmeticException if {@code v} is the null vector. */ public ArrayFieldVector<T> projection(ArrayFieldVector<T> v) throws DimensionMismatchException, MathArithmeticException { return (ArrayFieldVector<T>) v.mapMultiply(dotProduct(v).divide(v.dotProduct(v))); }
/** {@inheritDoc} */ public FieldVector<T> projection(FieldVector<T> v) throws DimensionMismatchException, MathArithmeticException { return v.mapMultiply(dotProduct(v).divide(v.dotProduct(v))); }
/** {@inheritDoc} */ public T dotProduct(FieldVector<T> v) throws DimensionMismatchException { try { return dotProduct((ArrayFieldVector<T>) v); } catch (ClassCastException cce) { checkVectorDimensions(v); T dot = field.getZero(); for (int i = 0; i < data.length; i++) { dot = dot.add(data[i].multiply(v.getEntry(i))); } return dot; } }
/** Find the orthogonal projection of this vector onto another vector. * @param v vector onto which {@code this} must be projected * @return projection of {@code this} onto {@code v} * @throws DimensionMismatchException if {@code v} is not the same size as * {@code this} * @throws MathArithmeticException if {@code v} is the null vector. */ public ArrayFieldVector<T> projection(ArrayFieldVector<T> v) throws DimensionMismatchException, MathArithmeticException { return (ArrayFieldVector<T>) v.mapMultiply(dotProduct(v).divide(v.dotProduct(v))); }
/** {@inheritDoc} */ public FieldVector<T> projection(FieldVector<T> v) throws DimensionMismatchException, MathArithmeticException { return v.mapMultiply(dotProduct(v).divide(v.dotProduct(v))); }
/** {@inheritDoc} */ public T dotProduct(FieldVector<T> v) throws DimensionMismatchException { try { return dotProduct((ArrayFieldVector<T>) v); } catch (ClassCastException cce) { checkVectorDimensions(v); T dot = field.getZero(); for (int i = 0; i < data.length; i++) { dot = dot.add(data[i].multiply(v.getEntry(i))); } return dot; } }