-
-
Save bitsnaps/d504636df84a3098db9227773b41abcd to your computer and use it in GitHub Desktop.
JScienceTest.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// reference http://www.geocities.jp/tomtomf/JScience/JScience.htm | |
// | |
@GrabResolver (name='jcurl-repository', root='http://jcurl.berlios.de/m2/repo/') | |
@Grab(group = 'org.jscience', module='jscience', version='4.3.1') | |
import org.jscience.mathematics.number.Complex | |
import org.jscience.mathematics.vector.ComplexMatrix | |
//計算結果の出力様関数 | |
def show(cm) { | |
int RowMax=cm.getNumberOfRows() | |
int ColMax=cm.getNumberOfColumns() | |
for(int i=0;i<RowMax;++i){ | |
for(int j=0;j<ColMax;++j){ | |
print "${cm.get(i, j)} " | |
} | |
println "" | |
} | |
} | |
//複素数配列を作り値を代入する | |
Complex [][] d =[ | |
[Complex.valueOf(1.0, 0.0),Complex.valueOf(-1.0, 0.0),Complex.valueOf(-1.0, 0.0)], | |
[Complex.valueOf(0.0,0.0),Complex.valueOf(30.0, 40.0),Complex.valueOf(0.0, 0.0)], | |
[Complex.valueOf(0.0, 0.0),Complex.valueOf(0.0, 0.0),Complex.valueOf(40.0, -30.0)] | |
] | |
//上記配列を行列計算用配列に代入する 配列1 | |
def cm =ComplexMatrix.valueOf(d) | |
//上記操作と同様に、配列計算用複素数配列に値を代入する | |
Complex [][] da =[ | |
[Complex.valueOf(0.0, 0.0)], | |
[Complex.valueOf(100.0, 0.0)], | |
[Complex.valueOf(100.0,0.0)] | |
] | |
//配列2 | |
def cm1 = ComplexMatrix.valueOf(da) | |
//配列1の逆行列に配列2の積を、複素配列anに代入する | |
def an = cm.inverse().times(cm1) | |
//計算結果の出力 | |
show(an) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment