ed
06-03-2008, 08:58 AM
This topic came up again briefly this morning, so I figured I'll post something quickly on it. I have played around with Groovy a little (others in the company more so), but find it a very interesting environment. Being so closely integrated with Java, it's quite easy to utilize the JMSL Library from the Groovy framework.
While I haven't written any real applications, using the GroovyConsole I have successfully called JMSL functions. On the installation side, it's easiest to copy the jmsl.jar archive into the groovy/lib directory so it is automatically included in the classpath. A system-wide CLASSPATH variable would also work. Then you can start up the GroovyConsole application and try some things out.
For example, my favorite basic starting point of calling a static function is the Error Function in the special functions class of the math package. In Groovy, this is as simple as:
import com.imsl.math.Sfun
println(Sfun.erf(0.5))
which gives the output as:
groovy> import com.imsl.math.Sfun
groovy> println(Sfun.erf(0.5))
0.5204998778130465
Couldn't be simpler! Stepping up to actually creating an object is just as easy. I'm sure some of this could be written more Groovy-like instead of Java-like, but the point is that it all works:
double[][] a = [[1, 3, 3],[1, 3, 4],[1, 4, 3]]
double[] b = [12, 13, 14]
import com.imsl.math.*
lu = new LU(a)
x = lu.solve(b)
//new PrintMatrix("x").print(x)
println("x = " + x)
ainv = lu.inverse()
new PrintMatrix("a inv").print(ainv)
And this generates the following output (ignoring the echo of the statements in the script). Using a 'code' tag here to retain the formatting of the output matrix.
x = [3.000000000000001, 2.0, 1.0]
a inv
0 1 2
0 7 -3 -3
1 -1 0 1
2 -1 1 0
And so there you have it. Get the jmsl.jar file on the classpath and import packages as usual.
While I haven't written any real applications, using the GroovyConsole I have successfully called JMSL functions. On the installation side, it's easiest to copy the jmsl.jar archive into the groovy/lib directory so it is automatically included in the classpath. A system-wide CLASSPATH variable would also work. Then you can start up the GroovyConsole application and try some things out.
For example, my favorite basic starting point of calling a static function is the Error Function in the special functions class of the math package. In Groovy, this is as simple as:
import com.imsl.math.Sfun
println(Sfun.erf(0.5))
which gives the output as:
groovy> import com.imsl.math.Sfun
groovy> println(Sfun.erf(0.5))
0.5204998778130465
Couldn't be simpler! Stepping up to actually creating an object is just as easy. I'm sure some of this could be written more Groovy-like instead of Java-like, but the point is that it all works:
double[][] a = [[1, 3, 3],[1, 3, 4],[1, 4, 3]]
double[] b = [12, 13, 14]
import com.imsl.math.*
lu = new LU(a)
x = lu.solve(b)
//new PrintMatrix("x").print(x)
println("x = " + x)
ainv = lu.inverse()
new PrintMatrix("a inv").print(ainv)
And this generates the following output (ignoring the echo of the statements in the script). Using a 'code' tag here to retain the formatting of the output matrix.
x = [3.000000000000001, 2.0, 1.0]
a inv
0 1 2
0 7 -3 -3
1 -1 0 1
2 -1 1 0
And so there you have it. Get the jmsl.jar file on the classpath and import packages as usual.