EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials Matlab Tutorial Matlab Integral
 

Matlab Integral

Priya Pedamkar
Article byPriya Pedamkar

Updated July 3, 2023

Matlab Integral

 

 

Introduction to Matlab Integral

Matlab Integral is useful in finding areas under the curves. It is the reverse of differentiation in calculus; hence, the functions are integrated by finding their anti-derivatives.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Integrals are of 2 types:

1. Indefinite integrals (Integrals without limits)

2. Definite integrals (Integrals with limits)

Syntax

Let us now understand the syntax of ‘integral function’ in MATLAB:

A = integral (Fx, Xminimum, Xmaximum)

Explanation:

1. ‘integral function’ will calculate the numeric integration of input function ‘Fx’

2. ‘Xminimum’ and ‘Xmaximum’ will be used as minimum and maximum limits for integration, respectively

3. If we want to use more specific options for integral, we can use the syntax:

A = integral (Fx, Xminimum, Xmaximum, Name, Value)

Examples to Implement Matlab Integral

Let us now understand how the code for ‘integral function’ looks like in MATLAB with the help of various examples:

Example #1

In this example, we will use a simple polynomial function of degree 2 and will integrate it between the limits 0 to 4. We will follow the following 2 steps:

Step 1: Create the function of degree 2 in MATLAB

Step 2: Use the integral function to calculate the integration

Code:

syms x
[Initializing the variable ‘x’] Fx = @(x) 4*x.^2
[Creating the polynomial function of degree 2] A = integral (Fx, 0, 4)
[Passing input function ‘Fx’ and the required limits to the ‘integral function’] [Mathematically, the integral of 4*x ^ 2, between the limits 0 to 4 is 85.3333]

Output:

integrate

Explanation: As we can see in the output, we have obtained the integral of our input function ‘Fx’ as 85.3333 using ‘integral function’, which is the same as we expected.

Example #2

In this example, we will use a polynomial function of degree 4 and will integrate it between the limits 0 to 2. We will follow the following 2 steps:

Step 1: Create the function of degree 4 in MATLAB

Step 2: Use the integral function to calculate the integration

Code:

syms x
[Initializing the variable ‘x’] Fx = @ (x) (4 * x.^4 + x.^3 -2 * x.^2 +1)
[Creating the polynomial function of degree 4] A = integral (Fx, 0, 2)
[Passing input function ‘Fx’ and the required limits to the ‘integral function’] [Mathematically, the integral of 4 * x. ^ 4 + x. ^ 3 -2 * x. ^ 2 +1, between the limits 0 to 2 is 26.2667]

Output:

degree 4

Explanation: As we can see in the output, we have obtained the integral of our input function ‘Fx’ as 26.2667 using ‘integral function’, which is the same as we expected.

Example #3

In this example, we will learn how to integrate a function between the limits 0 and infinity. For this example, we will use a function that combines logarithmic and exponential functions. The code will comprise of the following 2 steps:

Step 1: Create a function containing logarithmic and exponential functions

Step 2: Use the integral function to calculate the integration

Code:

syms x
[Initializing the variable ‘x’] Fx = @(x) exp(-x. ^3). * log(2 * x). ^3;
[Creating the function containing the exponential and logarithmic functions] A = integral (Fx, 0, inf)
[Passing input function ‘Fx’ and the required limits to the ‘integral function’. Note that we have passed ‘inf’ which signifies infinity, as the upper limit] [Mathematically, the integral of exp (-x. ^3). * log (2 * x). ^3, between the limits 0 to infinity is         -2.9160]

Output:

Matlab Integral3

Explanation: As we can see in the output, we have obtained the integral of our input function ‘Fx’ as -2.9160 using ‘integral function’, which is the same as we expected.

Example #4

In this example, we will learn how to use the syntax A = integral (Fx, Xminimum, Xmaximum, Name, Value)

For this example, we will use a vector function which is of the form [log(x) log(2x) log (3x) log (4x)]. The code will comprise of the following 2 steps:

Step 1: Create a function containing vector values

Step 2: Use the integral function to calculate the integration and add a ‘name-value pair’ argument

Code:

syms x
[Initializing the variable ‘x’] Fx = @(x) log((1 : 4) * x);
[Creating the function containing vector values] A = integral(Fx, 0, 2, 'ArrayValued', true)
[Passing input function ‘Fx’ and the required limits to the ‘integral function’. Note that we have passed ‘ArrayValued’, ‘true’, as the name value pair; which is used to calculate the integral of vector values]

Output:

Matlab Integral4

Explanation: As we can see in the output, we have obtained the integral of all the vector values in our array using the integral function and ‘name-value pair’ argument.

Conclusion

‘integral function’ can be used in MATLAB to calculate the integration of any function. We can set the desired limits on the integration using the arguments of the integral function. Applying specific conditions using ‘name-value pair’ arguments is also possible.

Recommended Articles

This is a guide to Matlab Integral. Here we discuss an introduction to Matlab Integral, syntax with explanation, examples with code, and output. You can also go through our other related articles to learn more –

  1. MATLAB Functions
  2. Matlab Alternatives
  3. Transfer Functions in Matlab
  4. Matlab mesh()

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW