// plot_waved2.java a very basic, yet complete java plot application // y=f(x) x in 0.0 to 1.0, and y in -1.0 to 1.0 import java.awt.*; import java.awt.event.*; import java.awt.geom.Line2D; import javax.swing.*; public class plot_waved2 extends Frame { int wsize = 1000; int xoff = 20; // frame int yoff = 60; // frame down int ymid = yoff+(wsize-xoff-yoff)/2; double xscale = (double)(wsize-xoff-xoff); double yscale = (double)(wsize-xoff-yoff); double xmin = 0.0; double xmax = 1.0; int nx = 512; double dx = (xmax-xmin)/(double)(nx-1); double x1, y1, x2, y2; int xp1, yp1, xp2, yp2; double f(double x) // y = f(x) 0.0 <= y <= 1.0 { double y = 0.0; double r = 1.0; double Pi = Math.PI; y = (12.56637062 + 113.0973356*Math.sin(x*Pi))*Math.cos(125.6637062*x)+ 2.827433389*Math.cos(x*Pi)*Math.sin(125.6637062*x); return y/125.0; } // end y // # plot_wave.mws // # r = (0.1+0.9*sin(x*Pi)) // f(x) := (0.1 + 0.9*sin(x*Pi))*sin(20.0*x*2.0*Pi); // f(x) := (0.1 + 0.9 sin(x Pi)) sin(125.6637062 x) // fx(x) := (0.1 + 0.9*cos(x*Pi))*cos(20.0*x*2.0*Pi); // fx(x) := (0.1 + 0.9 cos(x Pi)) cos(125.6637062 x) // dx(x) := diff(f(x),x); // dx(x) := 2.827433389 cos(x Pi) sin(125.6637062 x) // + 125.6637062 (0.1 + 0.9 sin(x Pi)) cos(125.6637062 x) // simplify(fx(x)); // fx(x) := 0.1 cos(125.6637062 x) + 0.9 cos(125.6637062 x) cos(x Pi) // simplify(dx(x)); // dx(x) := (12.56637062 + 113.0973356 sin(x Pi)) cos(125.6637062 x) // + 2.827433389 cos(x Pi) sin(125.6637062 x) plot_waved2() { setTitle("plot_waved2"); setSize(wsize,wsize); setBackground(Color.white); setForeground(Color.black); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setVisible(true); this.addMouseListener (new mousePressHandler()); } class mousePressHandler extends MouseAdapter { public void mousePressed (MouseEvent e) { requestFocus(); System.out.println("press"); // debug print repaint(); System.exit(0); } } public void paint(Graphics g) { g.drawString("r = 0.1+0.9*cos(x*Pi) y = r*cos(20.0*x*2.0*Pi)",50,50); g.drawString("y=f(x) xmin=0, xmax=1, ymin=-1, ymax=1", wsize/2, 50); // draw boundary and y=0 g.setColor(Color.red); g.drawRect(xoff, yoff, wsize-xoff-xoff, wsize-xoff-yoff); g.drawLine(xoff, ymid, wsize-xoff, ymid); g.setColor(Color.black); // draw a wave for(int i=0; i