Professional Documents
Culture Documents
Phase 2 Activity 1 Integration MATLAB
Phase 2 Activity 1 Integration MATLAB
MATLAB
Phase 2
Activity 1 : Integration
Fecha: 27/04/2022
MATLAB
INT COMMAND
q The MATLAB Symbolic Toolbox allows the user to
symbolically differentiate and perform integrations.
q Integration can be thought of as the opposite of
differentiation (finding a derivative) and is even
sometimes called an antiderivative.
q It is commonly visualized as the area under a curve.
q Symbolic integration, or computation of primitives, is
performed using the int command. This command
allows you to calculate indefinite and definite integrals.
2
MATLAB
q For the calculation of indefinite integrals, the
following syntaxes are used: int(S) or int(S,var).
q It can be a complete symbolic expression or the
name of an existing symbolic expression.
q In the int(S) command, if the expression contains a
single symbolic variable, the calculation will be
performed with respect to that variable. If the
expression contains more than one variable, the
calculation will be carried out with respect to the
symbolic variable by default.
q The int(S,var) command is used to calculate the
derivative of an expression with more than one
symbolic variable. 3
MATLAB
q To compute definite integrals, these other forms of
the int command are used: int(S,a,b) or int(S,var,a,b).
q a and b are the limits of integration. These limits can be
numbers or symbolic variables.
q Integration is often a difficult process. Sometimes there may
not even be an answer to a given problem.
q MATLAB might not find a solution to the integration of an
equation. When this happens, MATLAB returns int(S) along
with a message of the type:
Explicit integral could not be found
4
MATLAB
Example:
>> syms x a b t;
>> int(x^-1)
ans =
log(x)
>> int(x^3)
ans =
x^4/4
>> int(sin(2*x), 0, pi/2)
ans =
1
>> int(sin(2*x), a, b)
ans =
sin(b)^2 - sin(a)^2
5
MATLAB
Example:
>> syms x; f = x^7; int(f, 0, 1)
ans =
1/8
>> syms x; f = 1/x; int(f, 1, 2)
ans =
log(2)
>> syms x; f = log(x)*sqrt(x); int(f, 0, 1)
ans =
-4/9
>> syms x; f = exp(-x^2); int(f, 0, inf)
ans =
pi^(1/2)/2
6
MATLAB
Example:
>> syms x n; f = x^n; int(f)
ans =
piecewise([n = -1, log(x)], [n <> -1, x^(n + 1)/(n + 1)])
>> syms x n; f = n^x; int(f)
ans =
n^x/log(n)
>> syms a b theta; f = sin(a*theta+b); int(f)
ans =
-cos(b + a*theta)/a
>> syms u; f = 1/(1+u^2); int(f)
ans =
atan(u)
7
MATLAB
q Unlike derivation, symbolic integration has certain
problems when looking for a solution:
q The integral, antiderivative or primitive may not exist.
q The integral, antiderivative or primitive exists but the
software is not able to find it.
q The software is capable of finding the solution, but the
physical characteristics of the equipment (memory) do not
allow it.
q It is necessary to be very cautious when obtaining a
solution from MATLAB
8
MATLAB
Example:
>> syms x, a; f = exp(-a*x^2); int(f, x, -inf, inf)
Warning: Explicit integral could not be found.
ans =
piecewise(
[a < 0, Inf],
[(0 <= Re(a) or abs(arg(a)) <= pi/2) and a <> 0, pi^(1/2)/a^(1/2)],
[Otherwise, int(1/exp(a*x^2), x = -Inf..Inf)])
>> syms x; syms a positive; f = exp(-a*x^2);int(f, x, -inf, inf)
ans =
pi^(1/2)/a^(1/2)
>> f = exp(-x^2); int(f)
ans =
(pi^(1/2)*erf(x))/2
9
DEFINITE INTEGRATION
• Q = integral(fun,xmin,xmax) numerically integrates
function fun from xmin to xmax using global adaptive quadrature and default error
tolerances.
• Q = integral(fun,xmin,xmax,name,value) specifies additional options with one or
more name,value pair arguments. For example, specify 'waypoints' followed by a vector
of real or complex numbers to indicate specific points for the integrator to use.
q = integral(fun,xmin,xmax,Name,Value) specifies additional options with one or more Name,Value pair arguments. For example,
specify 'WayPoints' followed by a vector of real or complex numbers to indicate specific points for the integrator to use.
We can define numerical integration as a set of algorithms commonly used to find the
numerical value of a function. It could also mean finding the numerical solution of a
differential equation.
From calculus you are probably familiar with the trapezoidal method, which divides the
region under a curve into a set of rectangles or panels. It then adds up the areas of the
individual panels to get the integral. This an example of integration
PARAMETERIZED
Improper Integral FUNCTION
SINGULARITY AT LOWER LIMIT
COMPLEX CONTOUR INTEGRATION USING
WAYPOINTS
VECTOR-VALUED FUNCTION
IMPROPER INTEGRAL OF OSCILLATORY FUNCTION
Quadrature Integration
MATLAB has two commands called quad and quad l that can
be used to perform quadrature integration. This type of
method is based on the idea that you can approximate the
area under a curve better using quadratic functions instead of
rectangles
- The quad function uses an adaptive Simpson’s rule
approaches to do numerical integration.
Simpson's rule is a method that calculates a definite
integral by calculating the area of overlap of parabolic
segments in the interval of integration and then adding
them.
-The quadl function uses Lobatto integration. This
is a more sophisticated type of adaptive
quadrature integration.
The downside of the quad and quadl functions is that they cannot
integrate a set of points.
Example:
Use quadrature integration to compute:
)/5
( 𝑒 7$8 𝑑𝑥
-
Solution:
The analytical answer to four decimal places is:
The quad function returns:
Using the trapz function we find a good answer but it differs in the seventh decimal place:
DERIVADAS: DIFF(S)
El calculo simbólico diferencial, p calculo de derivadas, se lleva a cabo
utilizando el comando diff, este comando tiene distintos parámetros por
ejemplo:
- diff(S)
- diff(S,var)
La letra S puede ser una expresión simbólica completa, si solo cuenta
con una variable simbólica, se llevará a cabo respecto a esa variable
Si la expresión contiene más de una variable, el cálculo se llevará a cabo
con respecto a la variable simbólica por defecto.
DERIVADAS: DIFF(S,VAR) O
DIFF(S,VAR,N)
Las segundas derivadas se pueden calcular mediante las sintaxis diff(S,n)
o diff(S,var,n) donde n es un número positivo-
Este comando se utiliza también para calcular la derivada de una
expresión con más de una variable simbólica.
EJEMPLO:
Para comenzar, elaboraremos el siguiente ejemplo donde se derive esta
ecuación:
g = 5*x^4
Colocaremos las variables a utilizar