Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

UNIVERSIDAD AUTONOMA DE NUEVO LEON

FACULTAD DE INGENIERIA MECANICA Y ELECTRICA

MATLAB
Phase 2
Activity 1 : Integration

Nombre: Matricula: Carrera:


Mauricio Villarreal Martínez 1849756 IMTC
Aldo Barrón García 1915695 IMTC
Diego Raúl Ramos Segovia 1960175 IMTC
Luis Ramón López Salinas 2078151 IMTC

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)integra numéricamente la función ”fun” de ”xmin a xmax”


usando la cuadratura adaptativa global y las tolerancias de error predeterminadas.

q = integral(fun,xmin,xmax,Name,Value)especifica opciones adicionales con uno o


más Name,Value argumentos de par. Por ejemplo, especifique 'WayPoints'seguido de un
vector de números reales o complejos para indicar puntos específicos para que los
use el integrador.
TIPO DE FUNCIONES DE INTEGRADO
FUN
Integrando, especificado como un identificador de función, que define la función que se
integrará desde xminhasta xmax.
Xmin
Límite inferior de x , especificado como un valor escalar real (finito o infinito) o un valor
escalar complejo (finito). Si xmino xmaxson complejos,
entonces integralaproxima la integral de trayectoria de xmina xmaxsobre una trayectoria
en línea recta.
Xmax
Límite superior de x , especificado como un número real (finito o infinito) o un número
complejo (finito). Si xmino xmaxson complejos, integralaproxima la integral de trayectoria
de xmina xmaxsobre una trayectoria en línea recta.
ARGUMENTOS NOMBRE-VALOR
AbsTol
Tolerancia de error absoluta, especificada como el par separado por comas que consta
de 'AbsTol'y un número real no negativo. Establece la tolerancia de error absoluta en
aproximadamente 12 lugares decimales de precisión.
RelTol
Tolerancia de error relativa, especificada como el par separado por comas que consta
de 'RelTol'y un número real no negativo. Establece la tolerancia de error relativa en
aproximadamente 9 dígitos significativos.
ArrayValue
Indicador de función con valores de matriz, especificado como el par separado por
comas que consta de 'ArrayValued'y un numérico o lógico 1 ( true) o 0( false). Indica
que el integrando es una función con valores de matriz.
WayPoints
Waypoints de integración, especificados como el par separado por comas que
consta de 'Waypoints’ un vector de números reales o complejos. Use
waypoints para indicar puntos en el intervalo de integración que le gustaría
que el integrador use en la malla inicial:
• Agregue más puntos de evaluación cerca de características interesantes
de la función, como extremos locales.
• Integre eficientemente a través de discontinuidades
del integrando especificando las ubicaciones de las discontinuidades.
• Realice integraciones de contorno complejas especificando números
complejos como puntos de ruta. Si xmin, xmaxo cualquier entrada
del vector de waypoints es compleja, entonces la integración se realiza
sobre una secuencia de trayectorias en línea recta en el plano complejo. En
este caso, todos los límites de integración y waypoints deben ser finitos.
EXAMPLE
Como primer paso Tenemos nuestra funcion en
este caso utilizaremos la funcion (FUN)
ajustamos la funcion a MATLAB; despues
Evaluamos la integral y le ponemos un limite,
luego de esto ya tendremos la integra de la
funcion.
MULTIDIMENSIONAL INTEGRATION
• We can compute multidimensional integrals in
MATLAB by using nested in statements. Suppose
that we wanted to compute the indefinite integral:
• ∫ ∫ ∫ 𝑥𝑦 $ 𝑧 & 𝑑𝑥𝑑𝑦𝑑𝑧

This can be done with:


Definite integration proceeds analogously.
We can calculate:
$ *
( ( 𝑥 $ 𝑦𝑑𝑥𝑑𝑦
) $
With the commands:

When computing multidimensional integrals in cylindrical and spherical coordinates,


be sure to enter the correct area and volumen elements – MATLAB will not do this
automatically.
Example:
Find the volume of a cylinder of height h and radius a. What is the volume of a cylinder
with radius a = 3.5 inches and height h = 5 inches?
Solution:
We will integrate using cylindrical coordinates with: 0 ≤ r ≤ a, 0 ≤ θ ≤ 2π, 0 ≤ z ≤ h

The volume element in cylindrical coordinates is:


dV = rdrdθdz

So the volume of a cylinder of height h and radius a is:


2π 1
.
𝑣 = ( ( ( 𝑟𝑑𝑟𝑑θ𝑑𝑧
- - -

The commands to implement this in MATLAB are:


The volume of a cylinder with radius a = 3.5 inches and height h = 5 inches is:
NUMERICAL INTEGRATION
• MATLAB can be used to perform trapezoidal integration by calling the trapz(x, y)
function. Here x and y are two arrays, x containing the domain over which the
integration takes place and y containing the function values at those points. Multiple
functions can be integrated simultaneously (over the same domain x) by passing a
multiple column argument y where each column contains the values of each
function.
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.

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

Y agregaremos el comando diff(g):

Obteniendo asi la respuesta que es 20*x^3

You might also like