I am trying to get the integral of a rather complicated function: $$ \int_{t_1}^{t_2}m_{\text{basal}}+m_{\text{size}}\exp\left(\frac{1}{2}\left(\ln(S_{t_1})+\frac{u-t_1}{t_2-t_1}(\ln(S_{t_2})-\ln(S_{t_1}))+\frac{\delta^2(t_2-u)(u-t_1)}{t_2-t_1}\right)\right) \mathrm{d} u $$ But since I had the feeling that it might be solvable by a computer algebra system, I plugged it into Mathematica and got a solution. However, the solution involves a square root of negative numbers and is therefore complex, which surprised me. The integrand is a real function and evaluation of the solution as well, since all complex parts cancel out at the end, magically. But I would like to avoid any complex parts. As a mathematica newbie, I am not too familiar with its functionalities. Is there any way to enforce the symbolic integration just using real functions? Or putting in some constraints of variables, like $t1<t2$, in order not to get a square-root of a negative number?
Even more problematic is that evaluating the solution showed complete nonsense results, when compared to numerical integration of the Integrand. The results of the numeric integration is in a range, I would have expected (due to values of the integrand). Any ideas why this happens?
Below you can find the code:
betaExample := 0.1 deltaExample := 0.1 mbasalExample := 0.1 msizeExample := 0.1 S0Example := 1.0 t1Example := 0.0 t2Example := 1.0 S1Example := 1.105170918 S2Example := 4.0552 exampleSub = {beta -> betaExample, delta -> deltaExample, msize -> msizeExample, mbasal -> mbasalExample, t1 -> t1Example, t2 -> t2Example, S1 -> S1Example, S2 -> S2Example}; examplifyExpression[expr_] := expr /. exampleSub Integrand = mbasal + msize* Exp[(1/2)*(Log[S1] + ((u - t1)/(t2 - t1))*(Log[S2] - Log[S1]) + (delta^2/4)*((t2 - u)*(u - t1))/(t2 - t1))] (* mbasal + E^(1/2 ((delta^2 (t2 - u) (-t1 + u))/(4 (-t1 + t2)) + Log[S1] + ((-t1 + u) (-Log[S1] + Log[S2]))/(-t1 + t2))) msize *) AnaInt1 = FullSimplify[Integrate[Integrand, {u, t1, t2}]] (* mbasal (-t1 + t2) + (2 Sqrt[2] msize Sqrt[t1 - t2] (-Sqrt[S2] DawsonF[(delta^2 (t1 - t2) - 4 Log[S1] + 4 Log[S2])/(4 Sqrt[2] delta Sqrt[t1 - t2])] + Sqrt[S1] DawsonF[(delta^2 (-t1 + t2) - 4 Log[S1] + 4 Log[S2])/(4 Sqrt[2] delta Sqrt[t1 - t2])]))/delta *) examplifyExpression[AnaInt1] (* 6.57826*10^23 + 0. I *) NIntegrate[examplifyExpression[Integrand], {u, t1Example, t2Example}] (* 0.206923 *)