예제 #1
0
 public CalculationResult Calculate(Func func, double begin, double end, double accuracy)
 {
     var sign = Math.Sign(end - begin);
     double[] temp = {Math.Min(begin, end), Math.Max(begin, end)};
     begin = temp[0];
     end = temp[1];
     var segments = InitialSegments/2;
     var res = double.PositiveInfinity;
     double prevRes;
     do {
         prevRes = res;
         segments *= 2;
         var h = (end - begin)/segments;
         res = (func.Calculate(begin) + func.Calculate(end))/2;
         for(var i = 1; i <= segments - 1; i++) {
             res += func.Calculate(begin + h*i);
         }
         res *= h;
     } while((Math.Abs(res - prevRes))/3 > accuracy);
     var acc = (Math.Abs(res - prevRes)) / 3;
     res *= sign;
     return new CalculationResult(res, segments, acc);
 }
예제 #2
0
파일: Func.cs 프로젝트: adduxa/compMath
 public Func(string mathNotation, Func<double, double> function)
 {
     _mathNotation = mathNotation;
     _function = function;
 }