1 package org.jgnuplot; 2 3 /** 4 * This class provides the samefunctionality as gnuplot simple.dem 5 * 6 * warning: this demo is SLOW on PCs without math coprocessors! 7 * 8 * From _Automatic_Control_Systems_, fourth ed., figure 6-14 transient response 9 * of a second-order system to a unit step input function 10 * 11 * @author Pander 12 */ 13 public final class ControlsDem { 14 private ControlsDem() { 15 } 16 17 public static void gnuplot() { 18 Plot.setGnuplotExecutable("gnuplot"); 19 Plot.setPlotDirectory("/tmp"); 20 21 Plot aPlot = new Plot(); 22 aPlot.setXRange("0", "13"); 23 aPlot.setKey("box"); 24 aPlot.setSamples("50"); 25 aPlot.setDummy("t"); 26 aPlot.addExtra("damp(t) = exp(-s*wn*t)/sqrt(1.0-s*s)"); 27 aPlot.addExtra("per(t) = sin(wn*sqrt(1.0-s**2)*t - atan(-sqrt(1.0-s**2)/s))"); 28 aPlot.addExtra("c(t) = 1-damp(t)*per(t)"); 29 aPlot.addExtra("# wn is undamped natural frequency"); 30 aPlot.addExtra("# s is damping factor"); 31 aPlot.addExtra("wn = 1.0"); 32 aPlot.pushGraph(new Graph("s=.1,c(t)")); 33 aPlot.pushGraph(new Graph("s=.3,c(t)")); 34 aPlot.pushGraph(new Graph("s=.5,c(t)")); 35 aPlot.pushGraph(new Graph("s=.7,c(t)")); 36 aPlot.pushGraph(new Graph("s=.9,c(t)")); 37 aPlot.pushGraph(new Graph("s=1.0,c(t)")); 38 aPlot.pushGraph(new Graph("s=1.5,c(t)")); 39 aPlot.pushGraph(new Graph("s=2.0,c(t)")); 40 aPlot.addExtra("# plot c(t) for several different damping factors s"); 41 aPlot.setOutput(Terminal.PNG, "test/out/controls-01.png"); 42 try { 43 aPlot.plot(); 44 } 45 catch (Exception e) { 46 System.err.println(e); 47 System.exit(1); 48 } 49 } 50 }