i have a question regarding the outcomes of the integration in general.
Today i recognized something strange.
My problem contains an unknown parameter $\gamma$. It also contains two constant parameters $A$ and $B$ to which numerical values are assigned.
First i evaluated $f(x)=\gamma\int_{x=0}^{l}\frac{A}{B}\sin(x)dx$ like a "symbolic" Integration in Mathematica.
Afterwards i wanted to validate this result by calculating the integrand from above via NIntegrate[].
To my surprise both numerical results differ in a non-negligible way.

Can anybody tell me what mistake i made that both results are different?
(is it because of the accuracy? If so can you please explain i to me?)
I really appreciate every hint from you guys ;-)

  • 3
    $\begingroup$ Not knowing how you coded the problem makes it hard to say why the results are different. Please include code that reproduces the problem. (I get equivalent results.) $\endgroup$
    – Michael E2
    Commented Apr 29, 2021 at 19:33

1 Answer 1


As it has been pointed out, it is difficult to suggest what is going wrong without access to the code.

Below is what I tried as I was reading your post, which gives consistent results.

Since we are interested in comparing numerics and analytics I define a rule that specifies some values.

rule = {l -> 2, A -> 1, B -> 3};

The analytic integration and then imposing the aforementioned numerical values

a = (\[Gamma] Integrate[A/B Sin[x], {x, 0, l}]) /. rule

The NIntegrate result

b = With[{l = 2, A = 1, 
   B = 3}, \[Gamma] NIntegrate[A/B Sin[x], {x, 0, l}]]

Finally, we check if they are equivalent

(a - b) // Simplify // Chop

Since the above gives zero, we are happy. Note that without the Chop the result of the subtraction is of the order $\sim \mathcal{O}(\gamma \cdot10^{-16})$


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.