/// <summary> /// Compute a new Time Series based on input series s /// and polynomial equation. /// /// Returned series has a time range specified by t1 and t2. /// Points outside the range of the polynomial equation (min,max) /// are flaged as Point.MissingValueFlag /// </summary> /// <param name="s">input time Series</param> /// <param name="poly">polynomial equation</param> /// <param name="t1">starting time for new series</param> /// <param name="t2">ending time for new series</param> /// <returns>Time Series</returns> public static Series Polynomial(Series s, PolynomialEquation poly, DateTime t1, DateTime t2) { int sz = s.Count; Series rval = s.Clone(); for (int i = 0; i < sz; i++) { Point point = s[i]; if (point.BoundedBy(t1, t2)) { Point newPt; if (point.BoundedBy(t1, t2, poly.Min, poly.Max)) { newPt = new Point(point.DateTime, poly.Eval(point.Value), PointFlag.Computed); } else { newPt = new Point(point.DateTime, Point.MissingValueFlag, PointFlag.Missing); } rval.Add(newPt); } } return(rval); }
public static Series Polynomial(Series s, PolynomialEquation[] polyList, DateTime[] polyDateList1, DateTime[] polyDateList2, DateTime t1, DateTime t2) { int sz = s.Count; Series rval = s.Clone(); for (int i = 0; i < sz; i++) { Point point = s[i]; if (point.BoundedBy(t1, t2)) { Point newPt = new Point(point.DateTime, Point.MissingValueFlag, PointFlag.Missing); for (int p = 0; p < polyList.Length; p++) { PolynomialEquation poly = polyList[p]; if (point.BoundedBy(polyDateList1[p], polyDateList2[p], poly.Min, poly.Max)) { double val = poly.Eval(point.Value); if (val < 0) { Console.WriteLine("What we have a negative number?? " + point + " eval = " + poly.Eval(point.Value)); // throw new Exception(); } newPt = new Point(point.DateTime, val, PointFlag.Computed); break; } } rval.Add(newPt); } } return(rval); }