You have the following equation in "Fixed relation" page:
q=f*p/(f+s*p);

It will produce run time error when  f+s*p=0;

You should have check
if(Math.abs(f+s*p)<1.e-6){// or whatever small value which is enough for your case
q=
}else q=f*p/(f+s*p);