在看了许多讨论之后,例如:
我仍然被困住了,无法使下列代码工作:
import org.apache.commons.math3.linear;
class linearAlgebraLearning{
public static void main(String[] args){
// Create a real matrix with two rows and three columns, using a factory
// method that selects the implementation class for us.
double[][] matrixData = { {1d,2d,3d}, {2d,5d,3d}};
RealMatrix m = MatrixUtils.createRealMatrix(matrixData);
// One more with three rows, two columns, this time instantiating the
// RealMatrix implementation class directly.
double[][] matrixData2 = { {1d,2d}, {2d,5d}, {1d, 7d}};
RealMatrix n = new Array2DRowRealMatrix(matrixData2);
// Note: The constructor copies the input double[][] array in both cases.
// Now multiply m by n
RealMatrix p = m.multiply(n);
System.out.println(p.getRowDimension()); // 2
System.out.println(p.getColumnDimension()); // 2
// Invert p, using LU decomposition
RealMatrix pInverse = new LUDecomposition(p).getSolver().getInverse();
}
}下面是我一步一步地做的事情。
首先,我使用
sudo apt-get install libcommons-math3-java然后我查看了Common-math3-java安装的位置。
dpkg -L libcommons-math3-java
/.
/usr
/usr/share
/usr/share/maven-repo
/usr/share/maven-repo/org
/usr/share/maven-repo/org/apache
/usr/share/maven-repo/org/apache/commons
/usr/share/maven-repo/org/apache/commons/commons-math3
/usr/share/maven-repo/org/apache/commons/commons-math3/3.2
/usr/share/maven-repo/org/apache/commons/commons-math3/3.2/commons-math3-3.2.pom
/usr/share/maven-repo/org/apache/commons/commons-math3/debian
/usr/share/maven-repo/org/apache/commons/commons-math3/debian/commons-math3-debian.pom
/usr/share/doc
/usr/share/doc/libcommons-math3-java
/usr/share/doc/libcommons-math3-java/changelog.Debian.gz
/usr/share/doc/libcommons-math3-java/copyright
/usr/share/java
/usr/share/java/commons-math3.jar
/usr/share/maven-repo/org/apache/commons/commons-math3/3.2/commons-math3-3.2.jar
/usr/share/maven-repo/org/apache/commons/commons-math3/debian/commons-math3-debian.jar
/usr/share/java/commons-math3-3.2.jar然后我使用了(正如Install commons math library for java in Ubuntu中所讲的)
javac -cp .:/usr/share/java/commons-math3-3.2.jar linearAlgebraLearning.java 但是,我仍然是一个导入错误消息:
linearAlgebraLearning.java:1: error: cannot find symbol
import org.apache.commons.math3.linear;和额外的错误,因为编译器找不到类(如RealMatrix)。我知道这类问题已经问过很多次了。这里的人可能厌倦了这个问题..。但如果你能帮我我会很高兴的。
Ps :因为我的linux发行版上有Eclipse的一些bug,所以我不使用IDE,而是使用gedit和终端。
发布于 2019-07-29 02:38:19
我首先安装了每个libcommons包:
sudo apt install libcommons\*然后设置类路径:
export CLASSPATH="/usr/share/java/commons-math3.jar:/usr/share/java/commons-lang3.jar"您的java应该会自动地捡起它。我用jshell测试了它,它能够自动完成/导入BlockRealMatrix,例如:
jshell> import org.apache.commons.math3.linear.BlockRealMatrix
jshell> BlockRealMatrix foo = new BlockRealMatrix(2, 2);
foo ==> BlockRealMatrix{{0.0,0.0},{0.0,0.0}}https://stackoverflow.com/questions/33913675
复制相似问题