MATLAB Integration
MATLAB Integration
Home
MATLAB Integration
Programming
Java
Web
Databases
Academic
Management
Quality
Telecom
More...
Ad Options
MATLAB - Integration
Advertisements
Previous Page
Next Pag
In the first type, derivative of a function is given and we want to find the function. There
basically reverse the process of differentiation. This reverse process is known
differentiation, or finding the primitive function, or finding an indefinite integral.
MATLAB Basics
MATLAB - Home
MATLAB - Overview
MATLAB - Environment
MATLAB - Syntax
MATLAB - Variables
The second type of problems involve adding up a very large number of very small quant
then taking a limit as the size of the quantities approaches zero, while the number of term
infinity. This process leads to the definition of the definite integral.
Definite integrals are used for finding area, volume, center of gravity, moment of inertia, work d
force, and in numerous other applications.
respect to x is f(x). For example, since the derivative (with respect to x) of x2 is 2x, we can sa
MATLAB - Commands
MATLAB - M-Files
In symbols:
MATLAB - Operators
MATLAB - Decisions
2xdx = x2.
MATLAB - Loops
Indefinite integral is not unique, because derivative of x2 + c, for any value of a constant c, will als
MATLAB - Vectors
MATLAB - Matrics
2xdx = x2 + c.
MATLAB - Arrays
MATLAB - Colon Notation
MATLAB - Numbers
MATLAB - Strings
MATLAB - Functions
MATLAB provides an int command for calculating integral of an expression. To derive an expre
the indefinite integral of a function, we write:
int(f);
For example, from our previous example:
http://www.tutorialspoint.com/matlab/matlab_integration.htm
1/7
9/30/2014
MATLAB Integration
syms x
int(2*x)
MATLAB executes the above statement and returns the following result:
MATLAB Advanced
MATLAB - Plotting
Ads by SavePass 1.2
Ad Options
MATLAB - Graphics
MATLAB - Algebra
MATLAB - Calculus
MATLAB - Differential
MATLAB - Integration
MATLAB - Polynomials
MATLAB - Transforms
MATLAB - GNU Octave
MATLAB - Simulink
Selected Reading
Developer's Best Practices
Effective Resume Writing
Computer Glossary
Who is Who
ans =
x^2
Example 1
In this example, let us find the integral of some commonly used expressions. Create a script file
the following code in it:
syms x n
int(sym(x^n))
f = 'sin(n*t)'
int(sym(f))
syms a t
int(a*cos(pi*t))
int(a^x)
When you run the file, it displays the following result:
ans =
piecewise([n == -1, log(x)], [n ~= -1, x^(n + 1)/(n + 1)])
f =
sin(n*t)
ans =
-cos(n*t)/n
ans =
(a*sin(pi*t))/pi
ans =
a^x/log(a)
Example 2
Create a script file and type the following code in it:
syms x n
int(cos(x))
int(exp(x))
int(log(x))
int(x^-1)
int(x^5*cos(5*x))
pretty(int(x^5*cos(5*x)))
int(x^-5)
int(sec(x)^2)
pretty(int(1 - 10*x + 9 * x^2))
int((3 + 5*x -6*x^2 - 7*x^3)/2*x^2)
pretty(int((3 + 5*x -6*x^2 - 7*x^3)/2*x^2))
Note that the pretty command returns an expression in a more readable format.
When you run the file, it displays the following result:
ans =
sin(x)
ans =
http://www.tutorialspoint.com/matlab/matlab_integration.htm
2/7
9/30/2014
MATLAB Integration
exp(x)
ans =
x*(log(x) - 1)
ans =
log(x)
ans =
4 x sin(5 x)
x sin(5 x)
------------- + ----------25
5
ans =
-1/(4*x^4)
ans =
tan(x)
x (3 x
- 5 x + 1)
ans =
- (7*x^6)/12 - (3*x^5)/5 + (5*x^4)/8 + x^3/2
6
5
4
3
7 x
3 x
5 x
x
- ---- - ---- + ---- + -12
5
8
2
By definition, definite integral is basically the limit of a sum. We use definite integrals to find areas
the area between a curve and the x-axis and the area between two curves. Definite integrals can
used in other situations, where the quantity required can be expressed as the limit of a sum.
The int command can be used for definite integration by passing the limits over which you
calculate the integral.
To calculate
http://www.tutorialspoint.com/matlab/matlab_integration.htm
3/7
9/30/2014
MATLAB Integration
we write,
int(x, a, b)
For example, to calculate the value of
we write:
int(x, 4, 9)
MATLAB executes the above statement and returns the following result:
ans =
65/2
Following is Octave equivalent of the above calculation:
pkg load symbolic
symbols
x = sym("x");
f = x;
c = [1, 0];
integral = polyint(c);
a = polyval(integral, 9) - polyval(integral, 4);
display('Area: '), disp(double(a));
An alternative solution can be given using quad() function provided by Octave as follows:
pkg load symbolic
symbols
f = inline("x");
[a, ierror, nfneval] = quad(f, 4, 9);
display('Area: '), disp(double(a));
Example 1
Let us calculate the area enclosed between the x-axis, and the curve y = x32x+5 and the ordina
and x = 2.
The required area is given by:
4/7
9/30/2014
MATLAB Integration
Example 2
Find the area under the curve: f(x) = x2 cos(x) for 4 x 9.
Create a script file and write the following code:
f = x^2*cos(x);
ezplot(f, [-4,9])
a = int(f, -4, 9)
disp('Area: '), disp(double(a));
When you run the file, MATLAB plots the graph:
http://www.tutorialspoint.com/matlab/matlab_integration.htm
5/7
9/30/2014
MATLAB Integration
Previous Page
Print Version
PDF Version
Next Pag
Advertisements
ASP.NET | jQuery | AJAX | ANT | JSP | Servlets | log4j | iBATIS | Hibernate | JDBC | Struts | HTML5
http://www.tutorialspoint.com/matlab/matlab_integration.htm
6/7
9/30/2014
http://www.tutorialspoint.com/matlab/matlab_integration.htm
MATLAB Integration
Ad Options
7/7