javascript - Variables not converging... where's the error? -


i ported code in language. it's supposed run through probability estimations , continue running through them until converges on solution. convergence determined maximum change in probability getting below threshold. works in other language. on first iteration, max probability change should 50%, on second, should 22%, etc. , should converge fast.

however, in javascript, it's going 2 iterations before getting "stuck" , looping infinitely. i'm sure there's simple error here, can't seem find life of me. idea what's going on?

and here's fiddle: http://jsfiddle.net/lxlhuc0k/

var probs = new array();  (i=0; i<=99; i++) {     (j=0; j<=99; j++) {         (k=0; k<=99; k++){             probs[i,j,k]=.5;         }     } }  var maxchange=100;  while (maxchange>.01) {     maxchange=0;      (i=0; i<=99; i++) {         (j=0; j<=99; j++) {             (k=0; k<=99; k++){                 oldvalue=probs[i,j,k];                  probs[i,j,k]=math.max(                     .2125*getvalue(i,j,k+1)                     +.3900*getvalue(i,j,k+5)                     +.0920*getvalue(i,j,k+10)                     +.0370*getvalue(i,j,k+15)                     +.0560*getvalue(i,j,k+20)                     +.0008*getvalue(i,j,k+25)                     +.0016*getvalue(i,j,k+40)                     +.0001*getvalue(i,j,k+60)                     +.2100*(1-getvalue(j,i,0))                      ,1-getvalue(j,i+k,0)                 );                  if (math.abs(probs[i,j,k]-oldvalue)>maxchange) maxchange=math.abs(probs[i,j,k]-oldvalue);             }         }     }      alert(maxchange); }  alert('done!');  function getvalue(x, y, z) {     if (x+z>99)    return(1);     if (y>99) return(0);     return(probs[x,y,z]); } 


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -