You are a guest. Restricted access. Read more.

Special functions

You can use Java libraries in functions definitions, mixing freely Java and Python code. For example, consider Apache common math library. It has classes for special functions, see Special functions.

First,let us try to call, say, the “Beta” function:

from org.apache.commons.math3.special import Beta
a=Beta.regularizedBeta(0.1, 1, 0.3)
print a

The value returned by this function will be 0.0311138388027.

Now let us try to plot this function. We will use the same approach as in the previous section: we will build a class from this function and convert it to F1D.

Code example

  Download for this example is disabled for non-members
 1: from shplot import *
 2: from jhplot import *
 3: from org.apache.commons.math3.special import Beta
 5: class cmt(ifunc):
 6:    def value(self, v):
 7:       return Beta.regularizedBeta(v[0], self.p[0],self.p[1] )
10: p=cmt('regularizedBeta',1,2)  # create function object with one variable and 2 parameters
11: print p.dimension()           # print properties of this function
12: print p.numberOfParameters()
13: print p.parameterNames()
14: print p.variableNames()
15: print p.variableName(0)
16: p.setParameters([1,0.3])   # set parameters a=1, b=0.3
17: print p.value([0.1])       # print value of this function at x=0.1
19: f1=F1D(p,0.0,1)            # convert it to the F1D function and plot in 0.0-1
20: c1 = HPlot('Beta')
21: c1.visible()
22: c1.setAutoRange()
23: c1.draw(f1)

As you can see, you can mix Java, Jython and your custom code.

The above approach works only for Jython codding. A more general approach is to call Java directly and extend the class jhplot.FNon that is a pure-Java approach. In this case you can create not only Python scripts, but also write code in pure Java, or mix Java, Groovy and JRuby. Look at the section Non-parametric functions.