//Ref: erfc: http://dic.academic.ru/dic.nsf/ruwiki/453940 // Definition at MatLab: http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/erf.html&http://www.mathworks.com/cgi-bin/texis/webinator/search/?db=MSS&prox=page&rorder=750&rprox=750&rdfreq=500&rwfreq=500&rlead=250&sufs=0&order=r&is_summary_on=1&ResultCount=10&query=erf&submitButtonName=Search // We put commons-math.jar in // C:\Program Files\Java\j2re1.4.2_13\lib\ext and in // C:\Program Files\Java\jre1.5.0_10\lib\ext // Added this: import org.apache.commons.math.special.*; // Eclipse problems: access rules: // Way around: http://lkamal.blogspot.com/2008/09/eclipse-access-restriction-on-library.html // We used this: (Project) Properties -> Java Compiler -> Errors/Warnings // We did not use this: Windows -> Preferences -> Java -> Compiler -> Errors/Warnings // which stays different. // // Edit manually: http://www.eclipsezone.com/forums/thread.jspa?messageID=91952212 // doc: //http://www.java2s.com/Open-Source/Java-Document/Science/Apache-commons-math-1.1/org/apache/commons/math/special/Erf.java.htm // java-doc: http://commons.apache.org/math/api-1.0/overview-summary.html // download: http://www.java2s.com/Code/Jar/ABC/Downloadcommonsmath12jar.htm // http://www.java2s.com/Code/Jar/CatalogJar.htm // install: http://leepoint.net/notes-java/background/13files_and_directories/86packages-installing.html // import org.apache.commons.math.special.Erf; public class UFun { private final static boolean USECUSTOM=true; public static double erfh(double x, boolean HeavisideMode){ if(HeavisideMode)return x>0 ? 0.0 :1.0 ; if(USECUSTOM){ return UCFun.erfc(x); }else{ return erfc(x); } } //Apache version for test case: public static double erfha(double x, boolean HeavisideMode){ if(HeavisideMode)return x>0 ? 0.0 :1.0 ; return erfc(x); } //Wrapper to Apache library erf: public static double erfc(double x){ if(x<0)return 1.0-erfc(-x); try{ return (Erf.erf(-x*Math.sqrt(0.5))+1.0)*0.5; }catch(Exception ex){ return 0; } } //Test Case: public static double erfDerivative(double x, double step){ return (erfc(x)-erfc(x+step))/step; } } Copyright (C) 2009 Konstantin Kirillov