Search code examples
matlabfloating-pointprecisionnumerical-integration

Misunderstanding the integration of MATLAB


everybody!

Could you, guys, please explain why the answer for the exact integration

quad( @(x)x.^3-2.*x,0,2)

is

-2.220446049250313e-016

istead of a zero, just like it should be?


Solution

  • The quad function computes the integral numerically, not symbolically.

    Even though most integration methods will compute the integral of a 3rd degree polynomial 'exactly' , that is only true if all the calculations are done exactly as well. When doing the calculation on a computer, round-off error still is a factor.