Difference between integral and quad functions

15 次查看(过去 30 天)
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 个评论
george veropoulos
george veropoulos 2016-8-19
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

请先登录,再进行评论。

采纳的回答

Mike Hosea
Mike Hosea 2013-2-19
Well, the short answer is don't use QUAD for anything anymore. Here's why.
  1. 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.
  2. INTEGRAL can handle mild singularities at the end points.
  3. INTEGRAL can integrate over non-finite intervals.
  4. 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.
  5. INTEGRAL can handle vector-valued functions with the ArrayValued option (you can use QUADV for that).
  6. 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.
  7. 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 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by