I have a function $\sqrt{x^4(x+4)}$ to be integrated from 0 up to -4. Using Simpson's will give me 19.02 but using normal numerical methods giving me -19.5 !
What's the reason behind this difference in signs?
I have a function $\sqrt{x^4(x+4)}$ to be integrated from 0 up to -4. Using Simpson's will give me 19.02 but using normal numerical methods giving me -19.5 !
What's the reason behind this difference in signs?
Copyright © 2021 JogjaFile Inc.
Try using more segments for your quadrature formula. I've obtained $19.02$ using $h = 1$ step. Or you might have implemented Simpson's rule incorrectly.
Also the integrand is not quite good for numerical integration. Recall that Simpson's rule has a truncation error $$ \epsilon \sim h^4 \max_{x \in [a,b]} \left|f^{(4)}(x)\right| $$ and your function $f(x) = \sqrt{x^4 (x+4)} = x^2 \sqrt{x+4}$ has a derivative singularity at $x = -4$. The actual order of convergence will not be $4$, as for smooth functions. Thus methods, like Richardson interpolation or similar, relying on the order of the method, may fail.
Here's a table with Simpson's rule applied to $x^2\sqrt{x+4}$ on $[-4,0]$ with different stepsize $h$. One can determine the actual order of convergence $p^*$ which seems to be just $1.5$, not $4$ as for smooth functions.
$$ \begin{array}{ccccc} n&h&I_h&\Delta_{h} = |I_{2h} - I_{h}|&p^* = \log_2\frac{\Delta_{2h}}{\Delta_h}&\epsilon^*_h = \frac{\Delta_{h}}{2^{p^*} - 1}\\ \hline 4 &1.00000·10^0 &2.0341983057·10^1 &* &* &*\\ 8 &5.00000·10^{-1} &1.9825394258·10^1 &5.16589·10^{-1} &* &*\\ 16 &2.50000·10^{-1} &1.9622372473·10^1 &2.03022·10^{-1} &1.35 &1.31448·10^{-1}\\ 32 &1.25000·10^{-1} &1.9547084064·10^1 &7.52884·10^{-2} &1.43 &4.43764·10^{-2}\\ 64 &6.25000·10^{-2} &1.9519854911·10^1 &2.72292·10^{-2} &1.47 &1.54273·10^{-2}\\ 128 &3.12500·10^{-2} &1.9510120947·10^1 &9.73396·10^{-3} &1.48 &5.41578·10^{-3}\\ 256 &1.56250·10^{-2} &1.9506660644·10^1 &3.46030·10^{-3} &1.49 &1.90857·10^{-3}\\ 512 &7.81250·10^{-3} &1.9505433922·10^1 &1.22672·10^{-3} &1.50 &6.73737·10^{-4} \end{array} $$