/// <summary>Gets the value of the integral \int_a^b f(x) dx. /// </summary> /// <param name="lowerBound">The lower bound.</param> /// <param name="upperBound">The upper bound.</param> /// <returns>The value of \int_a^b f(x) dx.</returns> /// <remarks>The arguments must be elements of the domain of definition, represented by <see cref="IRealValuedCurve.LowerBound"/> and <see cref="IRealValuedCurve.UpperBound"/>.</remarks> public double GetIntegral(double lowerBound, double upperBound) { int sign = 1; if (upperBound > lowerBound) { sign = -1; var temp = upperBound; upperBound = lowerBound; lowerBound = temp; } var curveBuilderLowerBound = m_CurveBuilder.LowerBound; var curveBuilderUpperBound = m_CurveBuilder.UpperBound; /* we split the integral in parts which are outside and which are inside the range: */ if (lowerBound < curveBuilderLowerBound) { if (upperBound < curveBuilderLowerBound) { return(sign * m_LeftExtrapolator.GetIntegral(lowerBound, upperBound)); } double integralValue = m_LeftExtrapolator.GetIntegral(lowerBound, curveBuilderLowerBound); if (upperBound < curveBuilderUpperBound) { return(sign * (integralValue + m_CurveBuilder.GetIntegral(curveBuilderLowerBound, upperBound))); } return(sign * (integralValue + m_CurveBuilder.GetIntegral(curveBuilderLowerBound, curveBuilderUpperBound) + m_RightExtrapolator.GetIntegral(curveBuilderUpperBound, upperBound))); } else if (lowerBound > curveBuilderUpperBound) { return(sign * m_RightExtrapolator.GetIntegral(lowerBound, upperBound)); /* here we assume lowerBound < upperBound */ } if (upperBound <= curveBuilderUpperBound) { return(sign * m_CurveBuilder.GetIntegral(lowerBound, upperBound)); } return(sign * (m_CurveBuilder.GetIntegral(lowerBound, curveBuilderUpperBound) + m_RightExtrapolator.GetIntegral(curveBuilderUpperBound, upperBound))); }
/// <summary>Gets the value of the integral \int_a^b f(x) dx. /// </summary> /// <param name="lowerBound">The lower bound.</param> /// <param name="upperBound">The upper bound.</param> /// <returns>The value of \int_a^b f(x) dx.</returns> /// <remarks>The arguments must be elements of the domain of definition, represented by <see cref="IRealValuedCurve.LowerBound"/> and <see cref="IRealValuedCurve.UpperBound"/>.</remarks> public double GetIntegral(double lowerBound, double upperBound) { int sign = 1; if (upperBound > lowerBound) { sign = -1; var temp = upperBound; upperBound = lowerBound; lowerBound = temp; } var timeAtZero = m_CurveInterpolator.LowerBound; var timeAtLastPoint = m_CurveInterpolator.UpperBound; /* we split the integral in parts which are outside and which are inside the range: */ if (lowerBound < timeAtZero) { if (upperBound < timeAtZero) { return(sign * m_LeftExtrapolator.GetIntegral(lowerBound, upperBound)); } double integralValue = m_LeftExtrapolator.GetIntegral(lowerBound, timeAtZero); if (upperBound < timeAtLastPoint) { return(sign * (integralValue + m_CurveInterpolator.GetIntegral(timeAtZero, upperBound))); } return(sign * (integralValue + m_CurveInterpolator.GetIntegral(timeAtZero, timeAtLastPoint) + m_RightExtrapolator.GetIntegral(timeAtLastPoint, upperBound))); } else if (lowerBound > timeAtLastPoint) { return(sign * m_RightExtrapolator.GetIntegral(lowerBound, upperBound)); /* here we assume lowerBound < upperBound */ } if (upperBound <= timeAtLastPoint) { return(sign * m_CurveInterpolator.GetIntegral(lowerBound, upperBound)); } return(sign * (m_CurveInterpolator.GetIntegral(lowerBound, timeAtLastPoint) + m_RightExtrapolator.GetIntegral(timeAtLastPoint, upperBound))); }