//+++++++++++++++++++++++++++++++++++++++++++++++++++++ // File automatically generated by Xfuzzy - DO NOT EDIT //+++++++++++++++++++++++++++++++++++++++++++++++++++++ package pkg.xfsg.mfunc; import xfuzzy.lang.*; public class trapezoid extends ParamMemFunc { public trapezoid() { super("xfsg","trapezoid"); Parameter single[] = new Parameter[4]; single[0] = new Parameter("a"); single[1] = new Parameter("b"); single[2] = new Parameter("c"); single[3] = new Parameter("d"); setSingleParameters(single); } public double compute(double x) { double a = singleparam[0].value; double b = singleparam[1].value; double c = singleparam[2].value; double d = singleparam[3].value; return (x<a || x>d? 0: (x<b? (x-a)/(b-a) : (x<c?1 : (d-x)/(d-c)))); } public double greatereq(double x) { double a = singleparam[0].value; double b = singleparam[1].value; double c = singleparam[2].value; double d = singleparam[3].value; return (x<a? 0 : (x>b? 1 : (x-a)/(b-a) )); } public double smallereq(double x) { double a = singleparam[0].value; double b = singleparam[1].value; double c = singleparam[2].value; double d = singleparam[3].value; return (x<c? 1 : (x>d? 0 : (d-x)/(d-c) )); } public double center() { double a = singleparam[0].value; double b = singleparam[1].value; double c = singleparam[2].value; double d = singleparam[3].value; return (b+c)/2; } public double basis() { double a = singleparam[0].value; double b = singleparam[1].value; double c = singleparam[2].value; double d = singleparam[3].value; return (d-a); } public double[] deriv_eq(double x) { double[] deriv = new double[getNumberOfParameters()]; double a = singleparam[0].value; double b = singleparam[1].value; double c = singleparam[2].value; double d = singleparam[3].value; deriv[0] = (a<x && x<b ? (x-b)/((b-a)*(b-a)) : (x==a? 0.5/(a-b) : 0)); deriv[1] = (a<x && x<b ? (a-x)/((b-a)*(b-a)) : (x==b? 0.5/(a-b) : 0)); deriv[2] = (c<x && x<d ? (d-x)/((d-c)*(d-c)) : (x==c? 0.5/(d-c) : 0)); deriv[3] = (c<x && x<d ? (x-c)/((d-c)*(d-c)) : (x==d? 0.5/(d-c) : 0)); return deriv; } public double[] deriv_greq(double x) { double[] deriv = new double[getNumberOfParameters()]; double a = singleparam[0].value; double b = singleparam[1].value; double c = singleparam[2].value; double d = singleparam[3].value; deriv[0] = (a<x && x<b ? (x-b)/((b-a)*(b-a)) : (x==a? 0.5/(a-b) : 0)); deriv[1] = (a<x && x<b ? (a-x)/((b-a)*(b-a)) : (x==b? 0.5/(a-b) : 0)); deriv[2] = 0; deriv[3] = 0; return deriv; } public double[] deriv_smeq(double x) { double[] deriv = new double[getNumberOfParameters()]; double a = singleparam[0].value; double b = singleparam[1].value; double c = singleparam[2].value; double d = singleparam[3].value; deriv[0] = 0; deriv[1] = 0; deriv[2] = (c<x && x<d ? (d-x)/((d-c)*(d-c)) : (x==c? 0.5/(d-c) : 0)); deriv[3] = (c<x && x<d ? (x-c)/((d-c)*(d-c)) : (x==d? 0.5/(d-c) : 0)); return deriv; } public double[] deriv_center() { double[] deriv = new double[getNumberOfParameters()]; double a = singleparam[0].value; double b = singleparam[1].value; double c = singleparam[2].value; double d = singleparam[3].value; deriv[0] = 1; deriv[1] = 1; deriv[2] = 1; deriv[3] = 1; return deriv; } public double[] deriv_basis() { double[] deriv = new double[getNumberOfParameters()]; double a = singleparam[0].value; double b = singleparam[1].value; double c = singleparam[2].value; double d = singleparam[3].value; deriv[0] = -1; deriv[1] = 0; deriv[2] = 0; deriv[3] = 1; return deriv; } public boolean test () { double min = this.u.min(); double max = this.u.max(); double a = singleparam[0].value; double b = singleparam[1].value; double c = singleparam[2].value; double d = singleparam[3].value; return ( a<b && b<c && c<d && b>=min && c<=max ); } public void update() { if(!isAdjustable()) return; double[] pos = get(); double[] desp = getDesp(); boolean[] adj = getAdjustable(); double min = this.u.min(); double max = this.u.max(); double step = this.u.step(); double a = singleparam[0].value; double b = singleparam[1].value; double c = singleparam[2].value; double d = singleparam[3].value; pos = sortedUpdate(pos,desp,adj); if(pos[1]<min) { pos[1]=min; if(pos[2]<=pos[1]) pos[2] = pos[1]+step; if(pos[3]<=pos[2]) pos[3] = pos[2]+step; } if(pos[2]>max) { pos[2]=max; if(pos[1]>=pos[2]) pos[1] = pos[2]-step; if(pos[0]>=pos[1]) pos[0] = pos[1]-step; } updateValues(pos); } public String getEqualJavaCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " return (x<a || x>d? 0: (x<b? (x-a)/(b-a) : (x<c?1 : (d-x)/(d-c)))); "+eol; return code; } public String getGreqJavaCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " return (x<a? 0 : (x>b? 1 : (x-a)/(b-a) )); "+eol; return code; } public String getSmeqJavaCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " return (x<c? 1 : (x>d? 0 : (d-x)/(d-c) )); "+eol; return code; } public String getCenterJavaCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " return (b+c)/2; "+eol; return code; } public String getBasisJavaCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " return (d-a); "+eol; return code; } public String getEqualCCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " return (x<a || x>d? 0: (x<b? (x-a)/(b-a) : (x<c?1 : (d-x)/(d-c)))); "+eol; return code; } public String getGreqCCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " return (x<a? 0 : (x>b? 1 : (x-a)/(b-a) )); "+eol; return code; } public String getSmeqCCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " return (x<c? 1 : (x>d? 0 : (d-x)/(d-c) )); "+eol; return code; } public String getCenterCCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " return (b+c)/2; "+eol; return code; } public String getBasisCCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " return (d-a); "+eol; return code; } public String getEqualCppCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " return (x<a || x>d? 0: (x<b? (x-a)/(b-a) : (x<c?1 : (d-x)/(d-c)))); "+eol; return code; } public String getGreqCppCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " return (x<a? 0 : (x>b? 1 : (x-a)/(b-a) )); "+eol; return code; } public String getSmeqCppCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " return (x<c? 1 : (x>d? 0 : (d-x)/(d-c) )); "+eol; return code; } public String getCenterCppCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " return (b+c)/2; "+eol; return code; } public String getBasisCppCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " return (d-a); "+eol; return code; } }