public class LinAlg
extends java.lang.Object
This project was carried out at:
and supported byGenOpt Copyright (c) 1998-2021, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.
| Constructor and Description |
|---|
LinAlg() |
| Modifier and Type | Method and Description |
|---|---|
static double |
abs(double[] x)
calculates the absoulte value of a vector
|
static double[][] |
add(double[][] A,
double[][] B)
adds 2 matrices: C = A + B;
Note:C has the dimension of A; B must not have the same dimension as A (non existing element are considered as 0 and elements that are not in A but in B are not taken into account by the summation) |
static double[] |
add(double[] y,
double[] x)
adds 2 vectors: z = y + x
Note:If the dimension dx of x is bigger than the dimension dy of y, then only dx elements are added. |
static double[][] |
fillDiagonal(double[][] A,
double left,
double diagonal,
double right)
fills the diagonal matrix element and sets all other elements to zero.
|
static double[] |
gaussElimination(double[][] A,
double[] f)
solves a vector x by a Gauss elimination of a NxN matrix with
normalization and interchange of rows.
|
static double[] |
gaussEliminationTridiagonal(double[][] A,
double[] f)
solves a vector x by a Gauss elimination of a tridiagonal NxN
matrix with normalization and interchange of rows.
|
static double[] |
getCenter(double[][] M)
gets the center point of several points
|
static double[] |
getColumn(double[][] A,
int i)
gets a column of a matrix
|
static double[] |
getSub(double[] x,
int startIndex,
int number)
gets a part of a vector
|
static void |
initialize(double[][] A,
double v)
initializes a rectangular matrix
|
static void |
initialize(double[] A,
double v)
initializes a vector
|
static double |
innerProduct(double[] a,
double[] b)
calculates the inner product (dot product):
c[i] = sum(a[i] * b[i] , i = 0..N-1)
|
static double |
maxDiff(double[][] A,
double[][] B)
calculates the maximum magnitude of the difference between
corresponding matrix element, defined as
maxDiff = max(|A[i][j]-A[i][j]|) for all i,j
|
static double |
maxNorm(double[] u)
calculates the Lmax norm of a vector, defined as
Lmax(u) = (max(|u(i)|, i = 1..n)
|
static double |
maxNorm(double[][] A)
calculates Lmax norm of a matrix
The max norm of a matrix is the maximum row sum, where the row sum is the sum of the magnitudes of the elements in a given row |
static double[] |
multiply(double[][] A,
double[] u)
multiplicates a matrix with a vector: r = A * u;
(Returns the product of the row vector x and the rectangular array A) |
static double[][] |
multiply(double[][] A,
double[][] B)
multiplicates a matrix with a matrix: C = A * B;
|
static double[] |
multiply(double[] u,
double[][] A)
multiplicates a vector with a matrix: r = u^T * A;
(Returns the product of the row vector x and the rectangular array A) |
static double[] |
multiply(double s,
double[] u)
calculates S-multiplication : r = s * u;
|
static double[][] |
multiply(double s,
double[][] A)
calculates S-multiplication : B = s * A;
|
static double[] |
multiply(double s,
int[] u)
calculates S-multiplication : r = s * u;
The computations are done in
double. |
static double |
oneNorm(double[] u)
calculates L1 norm of a vector, defined as
L1(u) = (sum(u(i), i = 1..n)
|
static double |
oneNorm(double[][] A)
calculates L1 norm of a matrix
The one-norm of a matrix is the maximum column sum, where the column sum is the sum of the magnitudes of the elements in a given column. |
static double[][] |
outerProduct(double[] a,
double[] b)
calculates the outer product (Tensor product):
M[i][j] = a[i] * b[j]
|
static void |
print(double[] x)
prints a vector to the output stream
|
static void |
print(double[][] A)
prints a matrix to the output stream
|
static void |
print(double[] state,
java.lang.String delimiter)
reports a scalar and a vector to the output stream, where the
entries are separated by the given delimiter
|
static void |
print(double time,
double[] state)
reports a scalar and a vector to the output stream
|
static void |
print(double time,
double[] state,
java.lang.String delimiter)
reports a scalar and a vector to the output stream, where the
entries are separated by the given delimiter
|
static void |
print(int[] x)
prints a vector to the output stream
|
static double[][] |
setColumn(double[][] A,
double[] x,
int i)
sets a column of a matrix
Note: the dimension of x can be smaller than the column length of A |
static double[][] |
setRow(double[][] A,
double[] x,
int i)
sets a row of a matrix
Note: the dimension of x can be smaller than the row length of A |
static double[][] |
subtract(double[][] A,
double[][] B)
subtracts 2 matrices: C = A - B;
Note:C has the dimension of A; B must not have the same dimension as A (non existing element are considered as 0 and elements that are not in A but in B are not taken into account by the summation) |
static double[] |
subtract(double[] y,
double[] x)
subtracts 2 vectors: z = y - x;
Note: If the dimension dx of x is bigger than the dimension dy of y, then only dx elements are subtracted. |
static int[] |
subtract(int[] y,
int[] x)
subtracts 2 vectors: z = y - x;
Note: If the dimension dx of x is bigger than the dimension dy of y, then only dx elements are subtracted. |
static double |
sumColumn(double[][] A,
int i)
returns the sum of the elements in the i-th column
|
static double |
sumRow(double[][] A,
int i)
returns the sum of the elements in the i-th row
|
static double |
twoNorm(double[] u)
calculates the L2 norm of a vector, defined as
L2(u) = (sum(u(i)**2, i = 1..n) ^ 0.5
|
static double |
twoNorm(double[] u,
double h)
calculates the L2 norm with a scaling factor of a vector,
defined as L2(u) = (sum(h * u(i)**2, i = 1..n) ^ 0.5
|
public static double[] getCenter(double[][] M)
M - Matrix where the row are the points from which the
center has to be determined (the row has the first element
number, i.e. row i: A[i][0...dim])public static double maxDiff(double[][] A,
double[][] B)
A - rectangular matrixB - rectangular matrix of the same dimension like Apublic static double abs(double[] x)
x - the vectorx = ((sum(x(i)**2)**(1/2), i = 0..N-1)public static double[] getSub(double[] x,
int startIndex,
int number)
x - vectorstartIndex - index of first element that will be returnednumber - number of elements that will be returnedpublic static double[] getColumn(double[][] A,
int i)
A - matrixi - number of columnpublic static void initialize(double[] A,
double v)
A - vectorv - value to be set for all elementspublic static void initialize(double[][] A,
double v)
A - matrixv - value to be set for all elementspublic static double[][] setColumn(double[][] A,
double[] x,
int i)
A - matrixx - Vector to be set as the i-th column of Ai - column number where x has to be setpublic static double[][] setRow(double[][] A,
double[] x,
int i)
A - matrixx - Vector to be set as the i-th row of Ai - row number where x has to be setpublic static void print(double[][] A)
A - matrix to be printedpublic static void print(double[] x)
x - Vector to be printedpublic static void print(int[] x)
x - Vector to be printedpublic static double[][] fillDiagonal(double[][] A,
double left,
double diagonal,
double right)
A - square matrix to be filledleft - Element (i-1, j)diagonal - Element (i, j)right - Element (i+1, j)public static double oneNorm(double[][] A)
A - matrixpublic static double maxNorm(double[][] A)
A - matrixpublic static double oneNorm(double[] u)
u - Vectorpublic static double sumRow(double[][] A,
int i)
A - Matrixi - Row numberpublic static double sumColumn(double[][] A,
int i)
A - Matrixi - Column numberpublic static double twoNorm(double[] u)
u - Vectorpublic static double twoNorm(double[] u,
double h)
u - Vector
*param h Scaling factorpublic static double maxNorm(double[] u)
u - Vectorpublic static double[] subtract(double[] y,
double[] x)
x - Vector of size dxy - Vector of size dy (dy ≥ dx)public static int[] subtract(int[] y,
int[] x)
x - Vector of size dxy - Vector of size dy (dy ≥ dx)public static double[] add(double[] y,
double[] x)
x - Vector of size dxy - Vector of size dy (dy ≥ dx)public static double[][] add(double[][] A,
double[][] B)
A - Matrix of any dimensionB - Matrix of any dimensionpublic static double[][] subtract(double[][] A,
double[][] B)
A - Matrix of any dimensionB - Matrix of any dimensionpublic static double innerProduct(double[] a,
double[] b)
a - Arrayb - Arraypublic static double[][] outerProduct(double[] a,
double[] b)
a - Arrayb - Arraypublic static double[] multiply(double s,
double[] u)
s - Scalaru - Vectorpublic static double[] multiply(double s,
int[] u)
double.s - Scalaru - Vectorpublic static double[][] multiply(double s,
double[][] A)
s - ScalarA - Matrixpublic static double[] multiply(double[] u,
double[][] A)
u - VectorA - Matrixpublic static double[] multiply(double[][] A,
double[] u)
A - matrixu - vectorpublic static double[][] multiply(double[][] A,
double[][] B)
A - n x m matrixB - m x n matrixpublic static double[] gaussElimination(double[][] A,
double[] f)
A - Matrixf - Array with solution of A*x=fpublic static double[] gaussEliminationTridiagonal(double[][] A,
double[] f)
A - Matrixf - Array with solution of A*x=fpublic static void print(double[] state,
java.lang.String delimiter)
state - a vectordelimiter - a delimiterpublic static void print(double time,
double[] state,
java.lang.String delimiter)
time - a scalarstate - a vectordelimiter - a delimiterpublic static void print(double time,
double[] state)
time - A scalarstate - A vector