Advertisement
calcpage

LACS2013-FunctionMode.java

May 24th, 2013
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.79 KB | None | 0 0
  1. //FunctionMode.java MrG 2013.0521
  2. public class FunctionMode
  3. {
  4.     private double a;
  5.     private double b;
  6.     private double c;
  7.  
  8.     public FunctionMode(double a, double b, double c)
  9.     {
  10.         this.a = a;
  11.         this.b = b;
  12.         this.c = c;
  13.     }
  14.  
  15.     public void axes(double xMin, double xMax, double yMin, double yMax)
  16.     {
  17.         StdDraw.setPenRadius(.005);
  18.         StdDraw.line(0,yMin,0,yMax);
  19.         StdDraw.line(xMin,0,xMax,0);
  20.         StdDraw.text(xMax,-1,"x");
  21.         StdDraw.text(1,yMax,"y");
  22.     }
  23.  
  24.     public void plot(double xMin, double xMax)
  25.     {
  26.         StdDraw.setPenRadius(.01);
  27.         StdDraw.setPenColor(StdDraw.GREEN);
  28.         double x0 = xMin;
  29.         double y0 = a*xMin*xMin + b*xMin + c;
  30.         for(double xn=xMin; xn<=xMax; xn+=(xMax-xMin)/100)
  31.         {
  32.             double yn = a*xn*xn + b*xn + c;
  33.             StdDraw.line(x0,y0,xn,yn);
  34.             x0=xn;
  35.             y0=yn;
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement