APS Excellence in Physics Education Award
November 2019

Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

converting EJS to EJSS post and replies

Return to the converting EJS to EJSS thread
Login to post to this thread

what did i do wrong?
lookang Avatar
lookang
245 Posts

dear profs,

in java custom page, by Francisco Esquembre and Maria Jose Cano, Universidad de Murcia

public double xforce (double[] a, double[] b, int i) {
  if (i>=positives) return force;
  double d1 = a[i]-x0[i], d2 = b[i]-y0[i];
  double d = Math.sqrt(d1*d1+d2*d2);
  if (Math.abs(d)<1.0e-4) return 0;
  return -k*d1;
}

public double yforce (double[] a, double[] b, int i) {
  if (i>=positives) return 0.0;
  double d1 = a[i]-x0[i], d2 = b[i]-y0[i];
  double d = Math.sqrt(d1*d1+d2*d2);
  if (Math.abs(d)<1.0e-4) return 0;
  return -k*d2;
}


i convert to JavaScript
function xforce (a,b,i) {
  if (i>=positives) return force;
  var d1 = a[i]-x0[i];
  var d2 = b[i]-y0[i];
  var d = Math.sqrt(d1*d1+d2*d2);
  if (Math.abs(d)<1.0e-4) return 0;
  else return -k*d1;
}

function yforce (a,b,i) {
  if (i>=positives) return force;
  var d1 = a[i]-x0[i];
  var d2 = b[i]-y0[i];
  var d = Math.sqrt(d1*d1+d2*d2);
  if (Math.abs(d)<1.0e-4) return 0;
  else return -k*d2;
}


but it didn't seems to be affected by the value of k, the electric field strength

anyone can take a look and help debug?

i am converting this https://dl.dropboxusercontent.com/u/44365627/lookangEJSworkspace/export/Mosem2Simulations/Mosem2Simulations/ejs_MO_115S_126S_MicroscopicConductionModel.jar


to this
https://dl.dropboxusercontent.com/u/44365627/lookangEJSworkspace/export/ejss_src_driftvelocity.zip

thanks!

Attached File: ejss_src_driftvelocity.zip


OSP@SG blog
OSP@SG Digital Library

Replies to what did i do wrong?

Re: what did i do wrong? -
lookang Avatar
lookang
245 Posts

no worries i did it correctly, sort of.

https://dl.dropboxusercontent.com/u/44365627/lookangEJSworkspace/export/ejss_model_driftvelocity/driftvelocity_Simulation.xhtml

enjoy!

my yesterday error was the confusion of k with force.

i also sort of created this guide http://weelookang.blogspot.sg/2015/05/how-to-recreate-ejss-models-from-ejs.html to benefit EJS to EJSS conversion enthusiasts

Post edited May 18, 2015 at 8:00 PM EST.

Attached File: 2015-05-19_0757.png


OSP@SG blog
OSP@SG Digital Library


OSP Projects:
Open Source Physics - EJS Modeling
Tracker
Physlet Physics
Physlet Quantum Physics
STP Book