This discussion is archived
5 Replies Latest reply: Mar 14, 2013 6:49 AM by KonTiki RSS

Java Function Plotting Library

KonTiki Newbie
Currently Being Moderated
I need a flexible function plotting program in Java so I can see how different factors in a math model evaluate over the interval of interest, as well as see how the total effect (i.e. algebraic sum of all factors) looks like.
I do not possess Matlab or Mathematica - and I sure as hell won't be buying either of them. Besides, I see no reason why Java cannot be adapted to do work like this given Java's rich GUI possibilities.

Doing a Google search for Java function plotting libraries last week, I found what seemed to be the right tool.
This has a Plot class/method which used some Graphics2D class for the whole GUI, a Function class (this generated arrays of x and y values for the plotting and had getX & getY methods) as a parameter plus other parameters like xmin, xmx, number of points, etc.

Foolishly, I did not bookmark the webpage in question and now just can't find it.
If this Java library sounds familiar to anyone please give me its name.
Or any other good Java function plotting classes/library.
  • 1. Re: Java Function Plotting Library
    KonTiki Newbie
    Currently Being Moderated
    OK.

    Let's rephrase this question.
    Let's say that I'm writing my own Java GUI to achieve the aforesaid function plotting task.

    Now, there's no issue coding out most of that GUI.
    Having JTextFields for the basic independent variable, x, like xAxisTitle, xmin, xmax, xDiv, noOfDataPoints, etc and passing these through to a Function class is no problem.
    (The Function class will generate (x, y) data pairs over the desired range [xmin, xmax].)
    The trouble arises when we try to send the text of our y = f(x) function from the GUI to our Function class.

    The Java compiler (unfortunately!) won't allow us a parametrize a code statement, e.g.
              y[i] = double (Expression(x) ;
    even if Expression is written as if it were Java code - e.g. f(x) = x ^2^  being written as f(x) = x*x ;
    
    So we need some means of parsing the string expression for f(x) extracted from the GUI and making it comprehensible and calculable within the Function class.
    
    Any ideas on this ?
    
    Edited by: KonTiki on 13-Mar-2013 10:50
    
    Edited by: KonTiki on 13-Mar-2013 10:51
    
    Edited by: KonTiki on 13-Mar-2013 10:52                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
  • 2. Re: Java Function Plotting Library
    Kayaman Guru
    Currently Being Moderated
    KonTiki wrote:
    So we need some means of parsing the string expression for f(x) extracted from the GUI and making it comprehensible and calculable within the Function class.

    Any ideas on this ?
    You already have the idea. You need to parse a text something representing a function. I'd be all over Google searching for a library (unless you're planning to write the parser yourself, which is probably beyond your skills(?)).
  • 3. Re: Java Function Plotting Library
    KonTiki Newbie
    Currently Being Moderated
    Kayaman,

    I've already looked through Google but saw nothing really useful.

    Originally I'd feared the scale of the expression parser.
    But looking at similar expression forms in Mathematica yesterday evening, e.g.

    f(x) = 3.0x ^2^ + 2.7 Sin(x) + 3.4 Cosh(x) + 2.0Pi Erfc((x-u)/s)

    suggested to me that it might not be too hard to parse out.
    Making the non-polynomial functions start with a capital letter would help a bit.
    Likewise with putting their arguments within brackets.

    While it's surprising that Java aficionados - many of whom must have some use for data plotting - haven't already produced some classes for this task, it may well be a boon to those of us needing more practice.

    Edited by: KonTiki on 14-Mar-2013 04:29

    Edited by: KonTiki on 14-Mar-2013 04:30
  • 4. Re: Java Function Plotting Library
    Kayaman Guru
    Currently Being Moderated
    KonTiki wrote:
    Kayaman,

    I've already looked through Google but saw nothing really useful.
    Well, I'd be seriously amazed if there didn't exist useful libraries already. JFreeChart was suggested, but you might need a separate library for the expression parsing and the plotting.
    While it's surprising that Java aficionados - many of whom must have some use for data plotting - haven't already produced some classes for this task, it may well be a boon to those of us needing more practice.
    Some casual Googling turned up plenty of activity on plotting libraries, you just have to weed out the outdated and useless ones.
  • 5. Re: Java Function Plotting Library
    KonTiki Newbie
    Currently Being Moderated
    Largely answered thread.
    Some work demanded of user to match existing freeware to his/her own needs and preferences.

    Edited by: KonTiki on 14-Mar-2013 06:49

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points