This is the web version of EJS interface
EJS version 4.3.7
1. Title=Open Source Ejs Superposition of 2 Waves generated by equations
2. Author=Wolfgang Christian and Francisco Esquembre remix by lookang
3. Level=beginner
4. Abstract=http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=906.msg3393#msg3393
5. CaptureTools=false
6. DataTools=true
7. LanguageTools=true
8. EmersionSupport=false
9. AppletColSupport=false
10. UseInterpreter=true
11. DetectedFiles=./WaveFunctionPlotter/WaveFunctionPlotter.html;
12. AuxiliaryFiles=./WaveFunctionPlotter/;

Wave Function Plotter

NameValueTypeDimension
NameValueTypeDimension
NameValueTypeDimension

t=0;

Increment Time

double dx = (xmax-xmin)/n; // sample interval double x=xmin+dx/2; // position _view.trail.clear(); // clear old data _view.trail1.clear(); // need this else it will become a mess of points and make sure trail trail1 trail2 are names of the trail 2D element. _view.trail2.clear(); // need this else it will become a mess of points for(int i=0; i<n; i++) { // loop to create new data double u = _view.waveFunction.evaluate(x,t); // evaluate wave function _view.trail.addPoint(x,u) ; // add data to trace // added by wee for another functionplot1 double u1 = _view.waveFunction1.evaluate(x,t); // evaluate wave function _view.trail1.addPoint(x,u1); // add data to trace // added by wee for sum //sum = u+ u1 ; sum = _view.waveFunction.evaluate(x,t)+_view.waveFunction1.evaluate(x,t); _view.trail2.addPoint(x,sum); // summax = %sum_string%; x += dx; // increment position }
sum_string = fstring+"+"+fstring1; //sum_string = fstring+fstring1; // this method to fins Math.max does not work because sum = u +u1 find the sum of a particular answer but not the max point //sumabs = Math.abs(sum);/ //ymax = Math.max(2.0,sumabs);
_view.trail0.clear(); // need this else it will become a mess of points double u = _view.waveFunction.evaluate(x,0); // evaluate wave function double xnew = x+t*k1/pi; _view.trail0.addPoint(xnew,u); // add data to trace _view.trail10.clear(); // need this else it will become a mess of points double u1 = _view.waveFunction1.evaluate(x,0); // evaluate wave function double xnew1 = x-t*k2/pi; _view.trail10.addPoint(xnew1,u1); k1 = cal_speed(fstring); k2 = cal_speed(fstring1);

calspeed

public double cal_speed(String strTmp) { double temp; double coeff_x =1; double coeff_t =1; int tmp_start ; int tmp_end; // finding the constant x. Trying to extract coeff of x tmp_start = strTmp.indexOf('('); tmp_end = strTmp.indexOf("pi"); if ((tmp_end - tmp_start )!= 1) { coeff_x = Double.parseDouble (strTmp.substring (tmp_start+1, tmp_end-1)); } // finding the coeffient of t tmp_start = strTmp.indexOf('+'); if (tmp_start == -1) tmp_start = strTmp.indexOf('-'); tmp_end = strTmp.indexOf('t'); if ((tmp_end - tmp_start )!= 1) { coeff_t = Double.parseDouble (strTmp.substring (tmp_start+1, tmp_end-1)); } temp = coeff_t/coeff_x; return temp; }
EJSVIEW: Click link to view it's content
 Control variables:(testing)int
 title = "Superposition of 2 Waves generated by equations" layout = border visible = true location = "45,50" size = "600,600"
 position = center autoscaleX = false autoscaleY = true minimumX = xmin maximumX = xmax minimumY = -3 maximumY = 3 showAxes = true axesType = CARTESIAN3 titleX = "x" titleY = "u(x,t) and v(x,t)" TRmessage = "time="+_format(t,"0.00 ")
 variable = "x" functionx = "x" functiony = %fstring% javaSyntax = false visible = showFunction enabledPosition = false lineColor = color1 lineWidth = 3
 visible = showFunction enabledPosition = false norepeat = true connected = false lineColor = color1 lineWidth = 6
 variable = "x" functionx = "x" functiony = %fstring1% javaSyntax = false visible = showFunction1 enabledPosition = false lineColor = color2 lineWidth = 3
 visible = showFunction1 enabledPosition = false connected = false lineColor = color2 lineWidth = 6
 variable = "x" functionx = "x" functiony = %sum_string% javaSyntax = false visible = show_sum lineColor = colorsum lineWidth = 3
 visible = show_sum enabledPosition = false connected = false lineColor = colorsum lineWidth = 6
 visible = showFunction enabledPosition = false norepeat = true connected = false lineColor = 0,64,0 lineWidth = 6
 visible = showFunction1 enabledPosition = false connected = false lineColor = 0,128,255 lineWidth = 6
 position = south layout = VBOX
 layout = HBOX
 text = "x min=" alignment = RIGHT
 variable = xmin format = 0.0 action = _initialize() size = 45,24
 text = "x max=" alignment = RIGHT
 variable = xmax format = 0.0 action = _initialize() size = 45,24
 layout = HBOX
 position = west text = \$\Delta\$t = alignment = RIGHT
 position = center variable = dt editable = _isPaused() size = 45,24
 layout = HBOX
 position = west layout = HBOX
 variable = showFunction background = color1
 position = west text = " u(x,t)=" alignment = RIGHT background = color1
 position = center variable = %fstring% independent = "x,t" javaSyntax = false action = _initialize() size = 300,24
 options = "sin(pi*x-t);0.5*sin(pi*x-t);2*sin(pi*x-t);sin(0.5*pi*x-t);sin(2*pi*x-t);sin(pi*x-0.5*t);sin(pi*x-2*t);sin(pi*x-t-0.785);sin(pi*x-t-1.57)" variable = %fstring% background = color1
 position = east layout = HBOX
 variable = showFunction1 background = color2 foreground = WHITE
 position = west text = " v(x,t)=" alignment = RIGHT background = color2 foreground = WHITE
 position = center variable = %fstring1% independent = "x,t" javaSyntax = false action = _initialize() size = 300,24
 options = "sin(pi*x+t);0.5*sin(pi*x+t);2*sin(pi*x+t);sin(0.5*pi*x+t);sin(2*pi*x+t);sin(pi*x+0.5*t);sin(pi*x+2*t);sin(pi*x+t+0.785);sin(pi*x+t+1.57)" variable = %fstring1% background = color2 foreground = WHITE
 position = west layout = HBOX
 layout = HBOX borderType = LOWERED_ETCHED
 variable = n value = 8 minimum = 0 maximum = 50 format = "n = 00" closest = true dragaction = _initialize()
 variable = show_sum text = "Sum" background = colorsum
 variable = t minimum = 0.0 maximum = T format = "t = 0.00 s" tooltip = "time in seconds"
 variable = _isPaused tooltip = "Starts and stops the simulation." imageOn = /org/opensourcephysics/resources/controls/images/play.gif actionOn = _play() imageOff = /org/opensourcephysics/resources/controls/images/pause.gif actionOff = _pause()
 image = /org/opensourcephysics/resources/controls/images/stepforward.gif action = _step(); tooltip = "Steps the simulation."
 text = "-T/8" image = "/org/opensourcephysics/resources/controls/images/stepback.gif" action = dt = -dt; _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); dt = -dt; tooltip = "Steps the simulation."
 text = "T/8" image = "/org/opensourcephysics/resources/controls/images/stepforward.gif" action = _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); _step(); tooltip = "Steps the simulation."
 image = /org/opensourcephysics/resources/controls/images/reset1.gif action = t=0; tooltip = "Resets the time."
 image = /org/opensourcephysics/resources/controls/images/reset.gif action = _reset(); _initialize(); tooltip = "Resets the simulation."
 position = west layout = VBOX visible = false
 variable = sum_string