TransWikia.com

Can Mathematica Accurately Integrate the Absolute Value of Functions?

Mathematica Asked by DUO Labs on February 7, 2021

I have a function, and I want to find the antiderivative of the absolute value of a function $|f(x)|$.

Integrate[Abs[(6 + 5 Sin[3 x] + 7 Sin[4 x])^2 - 0.5], x, Assumptions -> Element[Alternatives[x], Reals]]

However, I want to know– is it correct on $[0, infty)$? I tried using NIntegrate to check it, and it only seemed off by a few decimal points. I don’t know if this signifies something fundamentally wrong with it, or just machine error?

One Answer

To get an accurate result, replace 0.5 by 1/2. Note, Alternatives[x] makes no sense, replace it by x. Make your tests with rational Numbers, not real ones and use Integrate not NIntegrate. Calculating with real numbers always gives slight differences. Finally, you can make a Monte Carlo Test with random rational Numbers to test your result. E.g.:

NumberOfTests = 10^2;
f[x_] = Integrate[Abs[(6 + 5 Sin[3 x] + 7 Sin[4 x])^2 - 1/2], x, 
   Assumptions -> Element[x, Reals]];
And @@ ( f'[x] == Abs[(6 + 5 Sin[3 x] + 7 Sin[4 x])^2 - 1/2] /. 
     x -> # & /@ (Table[RandomInteger[10^4], NumberOfTests]/
     Table[RandomInteger[10^4], NumberOfTests]))

Answered by Daniel Huber on February 7, 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