//Performs numerical integration private static float NIntCore(FunctionBounds Bounds, FunctionBaseCore FB) { //gets a new N space evaluation NFunctionalEqCore FE = new NFunctionalEqCore(FB, Bounds, true); float dv = FE.bounds.Aggregate(1.0f, (total, next) => total * next.Step); float val = FE.evalFlat().Sum(x => x[x.Count -1] * dv); //foreach(List<float> item in FE.evalFlat().) //{ // //for (int i = 0; i < FE.bounds.Length; i++) // //{ // // val += item[item.Count - 1] * (float)FE.bounds[i].Step; // //} // val += dv*item[item.Count-1]; //} return val; }
/// <summary> /// Creates bounds based on given input. This needs to be fixed so it isn't horrible. /// </summary> /// <param name="parts"></param> /// <returns></returns> public static FunctionBounds CreateBounds(string[] parts) { //This works for the time being. FunctionBounds Bounds = new FunctionBounds(); foreach (string part in parts.Skip(1)) { string[] bound = part.Split(','); for(int i = 0; i < bound.Length; i++) { if (bound[i].ToLower().EndsWith("pi")) { string temp = bound[i].Replace("*","").Replace("pi",""); if (temp == "") temp = "1"; bound[i] = (Convert.ToDouble(temp)*Math.PI).ToString(); } } if (bound.Length == 3) { Bounds.AddBound((float)Convert.ToDouble(bound.First()), (float)Convert.ToDouble(bound.Last()), (float)Convert.ToDouble(bound[1])); } else if (bound.Length == 2) { Bounds.AddBound((float)Convert.ToDouble(bound.First()), (float)Convert.ToDouble(bound.Last())); } else { Bounds.AddDefaultBound(); } } return Bounds; }
private static FunctionBounds ReduceBounds(FunctionBounds Bounds) { for (int j = 0; j < Bounds.BoundsList.Count; j++) { Bounds.BoundsList[j].Step = Bounds.BoundsList[j].Step / 2; } return Bounds; }