Java Array Sum sumProd(double[] v1, double[] v2, int i_, int n_)

Here you can find the source of sumProd(double[] v1, double[] v2, int i_, int n_)

Description

Calculates sum of products of n elements in input arrays, up to position i

License

Open Source License

Declaration

public static double sumProd(double[] v1, double[] v2, int i_, int n_) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /** Calculates sum of products of n elements in input arrays, up to position i */
    public static double sumProd(double[] v1, double[] v2, int i_, int n_) {
        //System.out.println("i_=" + i_ + ", n_=" + n_ + ", Multiplying:\n" + Utils.arrayString(v1) + " \nby\n" + Utils.arrayString(v2));
        double total = 0;
        for (int i = i_, n = 0; n < n_; i = i > 0 ? i - 1 : v1.length - 1, n++) {
            total += v1[i] * v2[i];// w ww . java  2  s .  c  o  m
        }
        //System.out.println("answer= " + total);
        return total;
    }
}

Related

  1. sumOfArray(final double[] array)
  2. sumOfMeanDifferencesOnePoint(double[] vector)
  3. sumOfMinimum(double[] a, double[] b)
  4. sumOfProducts(double[]... nums)
  5. sumOverVector(float[] a)
  6. sumRightShifts(int num, int... shifts)
  7. sumSquared(double[] a)
  8. sumToDouble(float[] array)
  9. sumToLong(byte[] array)