APS Excellence in Physics Education Award
November 2019

Science SPORE Prize
November 2011

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

## converting EJS to EJSS

what did i do wrong?

lookang
222 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

Current Replies - View all
Re: what did i do wrong?   (lookang - )