Here you can find the source of matrixVectorProductVDw(final double[][] V, final double[] d, final double[] w, final double[] a, int l1, int l2)
Parameter | Description |
---|---|
V | a quadratic <tt>l1</tt>-by-<tt>l2</tt> matrix |
d | the <tt>l2</tt> diagonal entries of a (diagonal) matrix |
w | a vector of length <tt>l2</tt> |
a | on return, contains <tt>V*D*w</tt> which is a vector of length <tt>l1</tt> |
l1 | number of rows of <tt>V</tt> |
l2 | number of columns of <tt>V</tt> |
public static void matrixVectorProductVDw(final double[][] V, final double[] d, final double[] w, final double[] a, int l1, int l2)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w . j a v a2 s . co m * Multiplies the matrix <tt>V</tt> (l1-by-l2) with diagonal matrix <tt>D</tt> (l2-by-l2) and * then with vector <tt>w</tt> (l2). The result is stored in the vector <tt>A</tt> (l1), * that is * * <pre> * A = V * D * w * </pre> * * If all diagonal entries of <tt>D</tt> are greater than zero, the * resulting matrix is also positive definite. * <p> * Note that this method does no safety checks (null or length). * * @param V * a quadratic <tt>l1</tt>-by-<tt>l2</tt> matrix * @param d * the <tt>l2</tt> diagonal entries of a (diagonal) matrix * @param w * a vector of length <tt>l2</tt> * @param a * on return, contains <tt>V*D*w</tt> which is a vector of length <tt>l1</tt> * @param l1 * number of rows of <tt>V</tt> * @param l2 * number of columns of <tt>V</tt> */ public static void matrixVectorProductVDw(final double[][] V, final double[] d, final double[] w, final double[] a, int l1, int l2) { assert hasShape(V, l1, l2); assert d != null; assert w != null; assert a != null; assert d.length >= l2; assert w.length >= l2; assert a.length >= l1; for (int i = 0; i < l1; i++) { // V D w a[i] = V[i][0] * d[0] * w[0]; for (int j = 1; j < l2; j++) { a[i] += V[i][j] * d[j] * w[j]; } } } /** * Returns whether matrix mat has size l1-by-l2 or not * @param mat a matrix * @param l1 first dimension (lines) * @param l2 second dimension (columns) * @return */ public static boolean hasShape(final double[][] mat, int l1, int l2) { assert mat != null; assert l1 > 0; assert l2 > 0; if (mat.length != l1) { return false; } for (int i = 0; i < mat.length; i++) { if (mat[i].length != l2) { return false; } } return true; } public static boolean hasShape(final double[][][] mat3d, int l1, int l2, int l3) { assert mat3d != null; assert l1 > 0; assert l2 > 0; assert l3 > 0; if (mat3d.length != l1) { return false; } for (int i = 0; i < mat3d.length; i++) { if (mat3d[i].length != l2) { return false; } for (int j = 0; j < mat3d[i].length; j++) { if (mat3d[i][j].length != l3) { return false; } } } return true; } }