Commons Mathはjavaの準正規ライブラリ的なのもの数学ライブラリ
統計計算などいろいろできて便利。
ライブラリできること
http://ja.wikipedia.org/wiki/Apache_Commons_Math
公式
http://commons.apache.org/
導入は
http://wiki.unfindable.net/webbook2/index.php/Hello_World!
を参照させていただきました。
とりあえず, javaでためす。
cygwinにjavacを導入。
windows用のjdkを
パスに以下のものを加える
.bashrc
export PATH="${PATH}:/cygdrive/c/Program Files/Java/jdk1.7.0_13/bin"
エラー表示が文字化けするのでこれも追加
alias javac="javac -J-Dfile.encoding=UTF-8"
http://commons.apache.org/
からダウンロード
commons-math3-3.1.1-bin.tar.gz
http://commons.apache.org/math/download_math.cgi
解凍後、作業フォルダに
commons-math3-3.1.1.jar
をコピー
連立方程式をとく。
x+3y=10
2x+5y=3
import org.apache.commons.math3.linear.*; public class test3{ public static void main(String[] args) { RealMatrix coefficients = new Array2DRowRealMatrix(new double[][]{{1, 3}, {2, 5}}); DecompositionSolver solver = new LUDecomposition(coefficients).getSolver(); RealVector constants = new ArrayRealVector(new double[]{10, 3},false); RealVector solution = solver.solve(constants); System.out.println(solution); } }
javac -cp "./*.jar" test3.java
実行
java -cp ".;./commons-math3-3.1.1.jar" test3
実行のほうは省略できない。それとカレントフォルダ.と"./common…"を
2つ指定しなくてはならない。
表示結果
{-41; 17}