/*
 * Oscillations.java by Richard J. Davies
 * from `Introductory Java for Scientists and Engineers'
 * chapter: `JSGL, a Scientific Graphics Library for Java'
 * section: `Example - Plotting a Function'
 *
 * We plot a simple function using the functionPlot method from the
 * JSGL to avoid having to write the plotting code ourselves.
 */
import uk.co.jscieng.*;


// The `OscFun' class is a wrapper for the method
// `f' to allow it to be passed as an argument.
class OscFun implements Plottable
{
  // The function to be plotted.
  public double f(double x)
  {
    if (x>0)
      return Math.sqrt(x) * Math.sin(1/x);
    else
      return Math.sin(1/x);
  }
}


// The class containing the main method
public class Oscillations
{
  public static void main(String[] argv)
  {
    // Set up the graph window.
    SciGraph.showGraph(-0.5, 0.5, -1.1, 1.1);

    // And plot the function
    SciGraph.functionPlot(new OscFun(), 0.1);
  }
}

