001 package lrs.lazyLRSEvaluators;
002
003 import lrs.*;
004 import fp.*;
005
006 public class LazyLambdaEval extends ALazyEval
007 {
008 double n=0.0;
009 // double fac = 1.0; // alternative technique to storing ncoef
010 double ncoef = 1.0; // alternative technique to storing nfac
011
012 public final LRStruct nextLRS()
013 {
014 n++;
015 // fac *= 2*n*(2*n+1); // for sine
016 // fac *= 2*n*(2*n-1); // for cosine
017
018 ncoef /= -2*n*(2*n+1); // for sine
019 // ncoef /= -2*n*(2*n-1); // for cosine
020
021 return makeLRS();
022 }
023
024 public final LRStruct makeLRS()
025 {
026 return makeLazyLRS ( new ILambda() {
027 double power = 2*n+1; // for sine
028 // double power = 2*n; // for cosine
029
030 // double coef = Math.pow(-1.0, n)/fac; // if fac is stored
031
032 double coef = ncoef; // if ncoef is stored
033
034 public Object apply(Object ... params) {
035 return coef*Math.pow(Math.PI*((Number) params[0]).doubleValue(),power);
036 }
037 public String toString() {
038 return coef+"*((PI*x)^"+power+")";
039 }
040 });
041 }
042 }