Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java库特征值浮点数_Java_Android_Shared Libraries_Eigenvalue_Jama - Fatal编程技术网

Java库特征值浮点数

Java库特征值浮点数,java,android,shared-libraries,eigenvalue,jama,Java,Android,Shared Libraries,Eigenvalue,Jama,嗨,我有Jama Library,但这个libraray只能用双倍数字工作,而且速度很慢。对于Android应用程序..最后我不需要如此高精度的eig反编译..所以有一些带有float num的JAva libaray..在语法上与jama类似吗?因为…我不想再写我的440行代码了,谢谢。eig。转置、逆等基本线性代数运算 或者存在相同的java库特征值。使用线程?或者您正在寻找类似的东西 import java.util.Arrays; public class Matrix {

嗨,我有Jama Library,但这个libraray只能用双倍数字工作,而且速度很慢。对于Android应用程序..最后我不需要如此高精度的eig反编译..所以有一些带有float num的JAva libaray..在语法上与jama类似吗?因为…我不想再写我的440行代码了,谢谢。eig。转置、逆等基本线性代数运算


或者存在相同的java库特征值。使用线程?

或者您正在寻找类似的东西

     import java.util.Arrays;

public class Matrix {

protected int rows;

protected int cols;

double[][] values;

public Matrix(int rows, int cols) {
    this.rows = rows;
    this.cols = cols;

    values = new double[rows][cols];

    for (int i = 0; i < rows; i++)
        for (int j = 0; j < cols; j++)
            values[i][j] = 0;

}

public Matrix(int[][] M) {
    this.rows = M.length;
    this.cols = M[0].length;

    values = new double[rows][cols];

    for (int i = 0; i < rows; i++)
        for (int j = 0; j < cols; j++)
            values[i][j] = M[i][j];
}

public Matrix(double[][] M) {
    this.rows = M.length;
    this.cols = M[0].length;

    values = new double[rows][cols];

    for (int i = 0; i < rows; i++)
        for (int j = 0; j < cols; j++)
            values[i][j] = M[i][j];
}

public void setToEye() {
    for (int i = 0; i < rows; i++)
        for (int j = 0; j < cols; j++)
            values[i][j] = (i == j) ? 1 : 0;

}

public static int[] matrixSize(Matrix M) {
    int[] size = new int[2];
    size[0] = M.rows;
    size[1] = M.cols;
    return size;
}

public static double vectMul(double[] A, double[] B) {
    double suma = 0;
    for (int i = 0; i < A.length; i++)
        suma += A[i] * B[i];

    return suma;
}

public static Matrix matrixTranspose(Matrix M) {
    int[] size = matrixSize(M);
    double[][] Mt = new double[size[0]][size[1]];

    for (int i = 0; i < size[0]; i++)
        for (int j = 0; j < size[1]; j++)
            Mt[i][j] = M.getValue(j, i);

    return new Matrix(Mt);
}

public static Matrix matrixMul(Matrix A, Matrix B) {
    int m1 = matrixSize(A)[0];
    int n1 = matrixSize(A)[1];
    int m2 = matrixSize(B)[0];
    int n2 = matrixSize(B)[1];
    double[][] rez;

    if (n1 != m2) {
        System.err.println("Inner matrix dimensions must agree!");
        return null;
    }

    rez = new double[m1][n2];
    for (int i = 0; i < m1; i++)
        for (int j = 0; j < n2; j++)
            rez[i][j] = vectMul(A.getRow(i), B.getColumn(j));

    Matrix r = new Matrix(rez);
    return r;
}

public static Matrix matrixMulWithMod(Matrix A, Matrix B, double mod) {
    int m1 = matrixSize(A)[0];
    int n1 = matrixSize(A)[1];
    int m2 = matrixSize(B)[0];
    int n2 = matrixSize(B)[1];
    double[][] rez;

    if (n1 != m2) {
        System.err.println("Inner matrix dimensions must agree!");
        return null;
    }

    rez = new double[m1][n2];
    for (int i = 0; i < m1; i++)
        for (int j = 0; j < n2; j++)
            rez[i][j] = vectMul(A.getRow(i), B.getColumn(j)) % mod;

    Matrix r = new Matrix(rez);
    return r;
}

public String toString() {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < this.rows; i++) {
        sb.append(Arrays.toString(values[i]));
        sb.append('\n');
    }

    String str = sb.toString();
    return str;
}

public double[][] getValues() {
    return values;
}

public void setValues(double[][] values) {
    this.values = values;
}

public void setValues(int[][] values) {
    for (int i = 0; i < rows; i++)
        for (int j = 0; j < cols; j++)
            this.values[i][j] = (double) values[i][j];
}

public double getValue(int row, int col) {
    return values[row][col];
}

public void setValue(int row, int col, double value) {
    values[row][col] = value;
}

public double[] getRow(int row) {
    double[] temp = new double[cols];
    for (int i = 0; i < temp.length; i++)
        temp[i] = values[row][i];
    return temp;

}

public double[] getColumn(int col) {
    double[] temp = new double[rows];
    for (int i = 0; i < temp.length; i++)
        temp[i] = values[i][col];
    return temp;
}

public double[] toDoubleArray() {
    double[] temp = new double[rows * cols];
    for (int i = 0; i < rows; i++)
        for (int j = 0; j < cols; j++)
            temp[i * (rows + 1) + j] = values[i][j];
    return temp;
}

public int[] toIntArray() {
    int[] temp = new int[rows * cols];
    for (int i = 0; i < rows; i++)
        for (int j = 0; j < cols; j++)
            temp[i * (rows + 1) + j] = (int) values[i][j];
    return temp;
}

public int getRowCount() {
    return this.rows;
}

public int getColumnsCount() {
    return this.cols;
}

public static double getMatrixDet(Matrix M) {
    int m = M.getRowCount();
    int n = M.getColumnsCount();

    double D = 0;

    if (m != n) {
        System.err.println("Matrix must be square!");
        System.exit(0);
    }

    if (n > 1) {
        Matrix I = new Matrix(m - 1, n - 1);

        for (int i = 1; i < m; i++)
            for (int j = 1; j < n; j++)
                I.setValue(i - 1, j - 1, M.getValue(i, j));

        D = M.getValue(0, 0) * getMatrixDet(I);
    } else
        D = M.getValue(0, 0);

    // za niz , kopira iz niza a elemente 0:i-1 i+1:n sredi za matrcu 
    Matrix I = new Matrix(m - 1, n - 1);
    for (int i = 1; i < n; i++) {
        I = M.withoutIthRowAndJthCol(i, 0);
        D = D + Math.pow((-1), i) * M.getValue(i, 0) * getMatrixDet(I);
    }
    return D;

}

public Matrix transpose() {
    Matrix temp = new Matrix(this.values);

    for (int i = 0; i < this.rows; i++)
        for (int j = 0; j < this.cols; j++)
            this.values[i][j] = temp.getValue(j, i);

    return this;
}

private Matrix withoutIthRowAndJthCol(int row, int col) {
    Matrix temp = new Matrix(this.rows - 1, this.cols - 1);
    int k = 0, l = 0;
    for (int i = 0; i < this.getRowCount(); i++) {
        if (i == row)
            continue;
        for (int j = 0; j < this.getColumnsCount(); j++) {
            if (j == col)
                continue;

            temp.setValue(k, l, this.values[i][j]);
            l++;
        }
        l %= 2;
        k++;
    }
    return temp;
}

public static Matrix getMatrixAdj(Matrix M) {
    int m = M.getRowCount();
    int n = M.getColumnsCount();

    Matrix A = new Matrix(m, n);

    if (m != n) {
        System.err.println("Matrix must be square!");
        System.exit(0);
    }

    for (int i = 0; i < m; i++)
        for (int j = 0; j < n; j++) {
            A.setValue(i, j, Math.pow((-1), i + j)
                    * getMatrixDet(M.withoutIthRowAndJthCol(i, j)));
        }
    A.transpose();
    return A;
}

public static Matrix matrixDiv(Matrix M, double n) {
    Matrix temp = M;

    for (int i = 0; i < M.getRowCount(); i++)
        for (int j = 0; j < M.getColumnsCount(); j++)
            temp.setValue(i, j, (M.getValue(i, j) / n));

    return temp;
}

public static Matrix getMatrixInv(Matrix M) {
    Matrix I = new Matrix(M.getRowCount(), M.getColumnsCount());

    if (M.getRowCount() != M.getColumnsCount()) {
        System.err.println("Matrix must be square!");
        System.exit(0);
    }
    if (getMatrixDet(M) == 0) {
        System.err.println("Matrix is singular!");
        System.exit(0);
    }
    I = matrixDiv(getMatrixAdj(M), getMatrixDet(M));
    return I;
}
}
导入java.util.array;
公共类矩阵{
受保护的整数行;
受保护的int cols;
双[][]值;
公共矩阵(整数行,整数列){
this.rows=行;
this.cols=cols;
值=新的双精度[行][cols];
对于(int i=0;i1){
矩阵I=新矩阵(m-1,n-1);
对于(int i=1;i