TransWikia.com

Symbolic integration vs. numerical integration

Mathematica Asked by WM_noob5 on June 13, 2021

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)=gammaint_{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 😉

One Answer

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})$

Correct answer by DiSp0sablE_H3r0 on June 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP