Open In App

Quad and Quadl in MATLAB

Improve
Improve
Like Article
Like
Save
Share
Report

The Quad and Quadl are built-in functions in MATLAB that allow you to approximate the definite integral of a function over a given interval.

Quad

It integrates a specified function over specified limits, based on adaptive Simpson’s rule. The adaptive rule seeks to improve accuracy by adaptively selecting the size of the subintervals (as opposed to keeping it constant) within the limits of integration while evaluating the sums that make up the integral.

Syntax

I = quad(‘fun’,a,b)

where fun is a function handle representing the function to be integrated, a is the lower bound of the interval, and b is the upper bound. The output, I, is the approximate value of the definite integral.

Uses

quad uses a numerical algorithm to approximate the definite integral. It can handle a wide range of functions, including those with singularities and discontinuities, and can provide high accuracy for well-behaved functions.

For example, to approximate the integral of the function funct(x) = x^2 from x = 0 to x = 2, we can use the following code:

Matlab




>> a = 0;
>> b = 2;
% first you have to create a function like here 'funct' is a function
%and then call that function.
%see the below output for more clarification.
>> I = quad('funct',a,b);


Output:

I = 2.6667  
%This means that the approximate 
value of the definite 
integral is 2.66667.  

 

Quadl

It integrates a specified function over specified limits, based on adaptive Lobatto quadrature. This one is more accurate than quad but it also uses more function evaluations. It may, however, be more efficient if your integrand is a smooth function. This function is a replacement of quad8 that existed in MATLAB 5.x. It uses a better and more reliable algorithm.

The syntax for quadl is the same as that for a quad.

Syntax

I = quadl(‘fun’,a,b)

Uses

Quadl is similar to quad, but it uses a different numerical algorithm to compute the integral. It can also handle a wide range of functions and can provide high accuracy for well-behaved functions.

For example, to approximate the integral of the function funct(x) = x^2 from x = 0 to x = 2, we can use the following code:

Matlab




>> a = 0;
>> b = 2;
% first you have to create a function like here 'funct' is a function
%and then call that function.
%see the below output for more clarification.
  
>> I = quadl('funct',a,b);
>> I


Output:

I = 2.66667  
%This means that the approximate
 value of the definite integral is 2.66667.

 

Advantages

  • Both ‘quad’ and ‘quadl’ are easy to use and require minimal input.
  • They can handle a wide range of functions, including those with singularities and discontinuities.
  • They can handle infinite intervals.
  • They can provide high accuracy for well-behaved functions.

Disadvantages

  • Both ‘quad’ and ‘quadl’ can be slow for highly oscillating or poorly behaved functions.
  • They can be less accurate for functions with singularities or discontinuities.
  • They may not work for certain types of functions, such as those with an infinite number of oscillations.

Conclusion

In conclusion, ‘quad’ and ‘quadl’ are useful functions in MATLAB for approximating the definite integral of a function over a given interval. They have several advantages, including ease of use and the ability to handle a wide range of functions, but they may not be suitable for all types of functions and may not always provide high accuracy.



Last Updated : 18 Jan, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads