Write a MATLAB mfile to evaluate the following integral inte
Solution
int(4^-x,0,2);
4^-x dx
=> du/dx = -1
à d(-x)/dx
à -1
à4^u(-1)du
à-4^udu
a f(x)dx=af(x)dx
à-4^udu
a^xdx=a^x/ln a
à-4^u/ln(4)
Substitute u = -x
à-4^(-x)/ln(4)
à-4^-x/ln(4)
Add Constant to solution
à4^-x\\ln (4)+C
Compute boundaries x = 0 to 2
= -1 /16ln(4) – (-1 / ln(4))
= 15 / 16 ln(4)
If f is a symbolic expression, then
int(f)
attempts to find another symbolic expression, F, so that diff(F) = f. That is, int(f) returns the indefinite integral or antiderivative of f (provided one exists in closed form). Similar to differentiation,
int(f,v)
uses the symbolic object v as the variable of integration, rather than the variable determined by symvar. See how int works by looking at this table.
int(expr,var)example
int(expr,var,a,b)example
int(___,Name,Value)example
Description
example
int(expr,var) computes the indefinite integral of expr with respect to the symbolic scalar variable var. Specifying the variable var is optional. If you do not specify it, int uses the default variable determined by symvar. If expr is a constant, then the default variable is x.
example
int(expr,var,a,b) computes the definite integral of expr with respect to var from a to b. If you do not specify it, int uses the default variable determined by symvar. If expr is a constant, then the default variable is x.
int(expr,var,[a,b]), int(expr,var,[a b]), and int(expr,var,[a;b]) are equivalent to int(expr,var,a,b).
example
int(___,Name,Value) uses additional options specified by one or more Name,Value pair arguments.
Examples
Indefinite Integral of Univariate Expression
Find an indefinite integral of this univariate expression:
syms x
int(-2*x/(1 + x^2)^2)
ans =
1/(x^2 + 1)
Indefinite Integrals of Multivariate Expression
Find indefinite integrals of this multivariate expression with respect to the variables x and z:
syms x z
int(x/(1 + z^2), x)
int(x/(1 + z^2), z)
ans =
x^2/(2*(z^2 + 1))
ans =
x*atan(z)
If you do not specify the integration variable, int uses the variable returned by symvar. For this expression, symvar returns x:
symvar(x/(1 + z^2), 1)
ans =
x
Definite Integrals of Univariate Expressions
Integrate this expression from 0 to 1:
syms x
int(x*log(1 + x), 0, 1)
ans =
1/4
Integrate this expression from sin(t) to 1 specifying the integration range as a vector:
syms x t
int(2*x, [sin(t), 1])
ans =
cos(t)^2
Integrals of Matrix Elements
Find indefinite integrals for the expressions listed as the elements of a matrix:
syms a x t z
int([exp(t), exp(a*t); sin(t), cos(t)])
ans =
[ exp(t), exp(a*t)/a]
[ -cos(t), sin(t)]
Apply IgnoreAnalyticConstraints
Compute this indefinite integral. By default, int uses strict mathematical rules. These rules do not let int rewrite asin(sin(x)) and acos(cos(x)) as x.
syms x
int(acos(sin(x)), x)
ans =
x*acos(sin(x)) + (x^2*sign(cos(x)))/2
If you want a simple practical solution, try IgnoreAnalyticConstraints:
int(acos(sin(x)), x, \'IgnoreAnalyticConstraints\', true)
ans =
-(x*(x - pi))/2
Ignore Special Cases
Compute this integral with respect to the variable x:
syms x t
int(x^t, x)
By default, int returns the integral as a piecewise object where every branch corresponds to a particular value (or a range of values) of the symbolic parameter t:
ans =
piecewise(t == -1, log(x), t ~= -1, x^(t + 1)/(t + 1))
To ignore special cases of parameter values, use IgnoreSpecialCases:
int(x^t, x, \'IgnoreSpecialCases\', true)
With this option, int ignores the special case t=-1 and returns only the branch where t<>–1:
ans =
x^(t + 1)/(t + 1)
Find Cauchy Principal Value
Compute this definite integral, where the integrand has a pole in the interior of the interval of integration. Mathematically, this integral is not defined.
syms x
int(1/(x - 1), x, 0, 2)
ans =
NaN
However, the Cauchy principal value of the integral exists. Use PrincipalValue to compute the Cauchy principal value of the integral:
int(1/(x - 1), x, 0, 2, \'PrincipalValue\', true)
ans =
0
Approximate Indefinite Integrals
If int cannot compute a closed form of an integral, it returns an unresolved integral:
syms x
F = sin(sinh(x));
int(F, x)
ans =
int(sin(sinh(x)), x)
If int cannot compute a closed form of an indefinite integral, try to approximate the expression around some point using taylor, and then compute the integral. For example, approximate the expression around x = 0:
int(taylor(F, x, \'ExpansionPoint\', 0, \'Order\', 10), x)
ans =
x^10/56700 - x^8/720 - x^6/90 + x^2/2
Approximate Definite Integrals
Compute this definite integral:
syms x
F = int(cos(x)/sqrt(1 + x^2), x, 0, 10)
F =
int(cos(x)/(x^2 + 1)^(1/2), x, 0, 10)
If int cannot compute a closed form of a definite integral, try approximating that integral numerically using vpa. For example, approximate F with five significant digits:
vpa(F, 5)
ans =
0.37571
Input Arguments
collapse all
expr — Integrand
symbolic expression | symbolic function | symbolic vector | symbolic matrix | symbolic number
Integrand, specified as a symbolic expression or function, a constant, or a vector or matrix of symbolic expressions, functions, or constants.
var — Integration variable
symbolic variable
Integration variable, specified as a symbolic variable. If you do not specify this variable, int uses the default variable determined by symvar(expr,1). If expr is a constant, then the default variable is x.
a — Lower bound
number | symbolic number | symbolic variable | symbolic expression | symbolic function
Lower bound, specified as a number, symbolic number, variable, expression or function (including expressions and functions with infinities).
b — Upper bound
number | symbolic number | symbolic variable | symbolic expression | symbolic function
Upper bound, specified as a number, symbolic number, variable, expression or function (including expressions and functions with infinities).
Name-Value Pair Arguments
Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (\' \'). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.
By definition, definite integral is basically the limit of a sum. We use definite integrals to find areas such as the area between a curve and the x-axis and the area between two curves. Definite integrals can also be used in other situations, where the quantity required can be expressed as the limit of a sum.
The int function can be used for definite integration by passing the limits over which you want to calculate the integral.
To calculate
Definite Integral
we write,
int(x, a, b)
FOR EXAMPLE:
f = x^3 - 2*x +5;
a = int(f, 1, 2)
display(\'Area: \'), disp(double(a));
MATLAB FILE ACTUAL PROBLEM:
syms x,q
f = 4 ^ -x
q=int(f,0,2)
disp(q)





