1
$\begingroup$

When I calculate the value of the following integral using Integrate, I receive an unexpected imaginary solution. I am using Mathematica 11.3.0.

Integrate[
  9.257208212146324`*^14 Cos[6.0415243338265245` x] Cos[30.207621669132624`x] 
    Sin[42.290670336785674` x] U[5, 0] U[7, 0],
  {x, 0, 0.52}
]
(* Out: (1.15009*10^14 - 0.0425289 I) U[5, 0] U[7, 0] *)
$\endgroup$
1
  • 4
    $\begingroup$ It seems to be on the order of round-off error (relative magnitude ~ $MachineEpsilon). $\endgroup$
    – Michael E2
    Commented Jun 12, 2020 at 4:27

1 Answer 1

2
$\begingroup$

This is due to precision issues with the floating-point math. Always use exact numbers with exact commands such as Integrate, else it might use numerical methods internally.

integrand = 
  9.257208212146324`*^14 Cos[6.0415243338265245` x] 
    Cos[30.207621669132624` x] Sin[42.290670336785674` x];
integrand0 = SetPrecision[integrand, Infinity]

integrand at high precision

 Integrate[integrand0 , {x, 0, 52/100}]

results of integration

N[%]
(* Out: 1.15009*^14 *)

numerical estimate of those results

$\endgroup$
4
  • 2
    $\begingroup$ Interesting/bizarre: SetPrecision[ Hold@Integrate[ 9.257208212146324`*^14 Cos[6.0415243338265245` x] Cos[ 30.207621669132624` x] Sin[42.290670336785674` x] U[5, 0] U[7, 0], {x, 0, 0.52}], 16] $\endgroup$
    – Michael E2
    Commented Jun 12, 2020 at 4:23
  • $\begingroup$ @MichaelE2 The main issues appears to be U[5, 0] U[7, 0]. When omitted, the integration is performed, although with the strange warning message about the precision of the argument function. $\endgroup$
    – bbgodfrey
    Commented Jun 12, 2020 at 18:48
  • $\begingroup$ @bbgodfrey For me the main issue is that the evaluation leaked outside of Hold. I would think that could be considered a bug. Consider SetPrecision[Hold[Sin[1]], 16] in which Sin is not evaluated. Evaluation also leaks if I replace Hold by HoldComplete. $\endgroup$
    – Michael E2
    Commented Jun 12, 2020 at 21:16
  • $\begingroup$ @MichaelE2 I see your point. Thanks. $\endgroup$
    – bbgodfrey
    Commented Jun 12, 2020 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.