DMelt:Math/4 Special Functions

From jWork.ORG
Jump to: navigation, search
Limitted access. Reguest membership or login to this link first if you are already a member

Special functions

The simplest way to create complicated functions including special function is to call external Java libraries. You can use any Java library in the function definitions, mixing freely Java and Python code (or any other scripting language). Here is a small example that creates 1-erf(x) function from Apache math3.special package. to define the "erf" function.

from  jhplot import *
from org.apache.commons.math3.special.Erf import *

class MyFunc(FNon):
      def value(self, x):
                return 1-erf(x[0])
c1 = HPlot()
c1.visible();   c1.setAutoRange()
pl = MyFunc("function",1,0)

The function "erf" is taken from Erf Java class. Here "MyFunc" is a class that defines a new function (1-erf) and returns its values. x[0] defines "x" (0 means one-dimensional function). You can also define functions in multiple dimensions using x[0], x[1], x[2] etc. notations.

The output of this script is shown in this plot:

DMelt example: Special function using Apache Common Math

The above approach works only for Jython/Python codding. A more general approach is to call Java directly and extend the class jhplot.FNon that is a pure-Java approach, as in the above example. 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 for more details.

As you can see, you can mix Java, Jython and your custom code. A beta function created with the above code is shown here:

DMelt example: Special (beta) function shown as F1D

Here is another example: let us plot a Crystal Ball function as defined wikipedia: Crystal Ball function . We will use the Python language to create this function, and then we will plot it:

with the output shown below:

Not allowed to read dmelt 20415788 : Not URL!

List of Java libraries for special functions

Here is a short list of special functions supported by DataMelt:

In addition, DataMelt supports distribution functions:

More information on this topic is in DMelt books