Derivative and Integration
Derivative
diff
is differentiate symbolic expression or function.
diff(F) % differentiates F with respect to the variable determined by symvar(F,1).
diff(F,var) % differentiates F with respect to the variable var.
diff(F,n) % computes the nth derivative of F with respect to the variable determined by symvar.
diff(F,var,n) % computes the nth derivative of F with respect to the variable var.
diff(F,var1,...,varN) % differentiates F with respect to the variables var1,...,varN.
Differentiate function
Find the derivative of the function sin(x^2).
Differentiation with respect to particular variable
Find the first derivative of this expression:
Now, find the derivative of this expression with respect to the variable t:
Higher-Order derivatives of univariate expression
Find the 4th, 5th, and 6th derivatives of this expression:
Higher-Order derivatives of multivariate expression with respect to particular variable
Find the second derivative of this expression with respect to the variable y:
Compute the second derivative of the expression xy. If you do not specify the differentiation variable, diff uses the variable determined by symvar. For this expression, symvar(xy,1) returns x. Therefore, diff computes the second derivative of x*y with respect to x.
If you use nested diff calls and do not specify the differentiation variable, diff determines the differentiation variable for each call. For example, differentiate the expression x*y by calling the diff function twice:
Mixed Derivatives
Differentiate this expression with respect to the variables x and y:
We can also compute mixed higher-order derivatives by providing all differentiation variables:
Integration
Definite integral
quad
and quadl
are used command of definite integral. Basically, quadl
is more powerful than quad
. If fun is a symbolic expression, then
Compute definite integral
To calculate the definite integral
Indefinite integral
If f is a symbolic expression, then type
int(f) attempts to find another symbolic expression, Fun, so that diff(F) = f. That is, int(f) returns the indefinite integral or antiderivative of f (provided one exists in closed form).
Uses the symbolic object vi
as the variable of integration, rather than the variable determined by symvar
.
Here are some examples to show how int
works.
To calculate the integral
int
can also be used to calculate the definite integral
However, if you try to calculate the integral without assigning a value to a, MATLAB assumes that a represents a complex number, and therefore returns a piecewise answer that depends on the argument of a. If you are only interested in the case when a is a positive real number, use assume to set an assumption on a. The assume function is especially useful when you run do integral for the distribution function.
Now you can calculate the preceding integral using the commands
This returns