Difference between integral and quad functions
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alexandru
el 15 de Feb. de 2013
Comentada: george veropoulos
el 19 de Ag. de 2016
Can someone briefly explain to me the difference between the integral and quad functions? I know that they will give different answers because of different algorithms but usually the results are close.
In my case I have a function of 2 variables f(x,y). Say I integrate over y from a to b using integral so I have
g(x) = integral(@(y) f(x,y),a,b).
Suppose now that I solve for the roots of g and I find a root at x_0. If I test this solution is correct by
integral(@(y) f(x_0,y),a,b) I get something of the power e^-17.
If instead I use quad(@(y) f(x_0,y),a,b) I get 0.0365.
Moreover whether I compute g(x) using integral or quad makes a huge difference as the solution x_0 I am getting from g(x)=0 is very different in the 2 cases.
1 comentario
george veropoulos
el 19 de Ag. de 2016
i wwant to use the integral bit the limits of intgration are vector.... when i rum my code the message Error using integral (line 86) A and B must be floating point scalars. are produce what i must do?? thank you in advance Goerge
Respuesta aceptada
Mike Hosea
el 19 de Feb. de 2013
Well, the short answer is don't use QUAD for anything anymore. Here's why.
- INTEGRAL supports mixed relative and absolute error control: specify the relative accuracy (essentially how many digits) you want with RelTol. You need AbsTol because relative error isn't defined when the true answer is zero. So RelTol is usually going to control the accuracy, but if the answer is small in magnitude, AbsTol will take over.
- INTEGRAL can handle mild singularities at the end points.
- INTEGRAL can integrate over non-finite intervals.
- INTEGRAL can perform piecewise-linear path integrals in the complex plane using the Waypoints options. The Waypoints option can also be used to improve efficiency for piecewise-defined functions on the real axis.
- INTEGRAL can handle vector-valued functions with the ArrayValued option (you can use QUADV for that).
- INTEGRAL uses a higher order method even than QUADL, so it is usually more accurate and efficient on smooth problems than either QUAD or QUADL.
- INTEGRAL starts with a much finer initial mesh than QUAD and is more conservative in how it controls the error. As a result it tends to be more reliable.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!