This blog will teach us how to find the function’s partial derivatives in MATLAB.
How to Find the Function’s Partial Derivative in MATLAB?
We can calculate the function’s partial derivatives in MATLAB using the built-in gradient() function. This function is used for calculating the partial derivative of the multivariate function (multiple inputs and single output) with respect to the specified variable. This function accepts the multivariate function as an input and returns its calculated partial derivative with respect to the given variable.
Syntax
The gradient() follows a simple syntax that is given below:
Here:
The function gradient(F, x) calculates the given function F’s one-dimensional partial derivative with respect to x.
The function gradient(F, [x, y]) computes the given function F’s partial derivatives with respect to x and y.
The function gradient(F, [x1, x2, x3,…,xN) finds the n-dimensional partial derivative of the function F with respect to the N components.
Examples
Follow the given examples to demonstrate the working of MATLAB’s gradient() function to compute the partial derivatives of the given function F.
Example 1: How to Calculate the Partial Derivatives of the Function with Single Input Using the Function gradient(F, x)?
In this example, we calculate the given function F’s partial derivatives with respect to x using the gradient() function.
Example 2: How to Calculate the Partial Derivatives of the Function with Two Inputs Using the Function gradient(F, [x, y])?
The given MATLAB code computes the function F’s partial derivatives with respect to x and y using the gradient() function.
Example 3: How to Calculate the Partial Derivatives of the Function with Three Inputs Using the Function gradient(F, [x, y, z])?
This example computes the given function F’s partial derivatives with respect to x, y, and z using the gradient() function.
Conclusion
MATLAB is a helpful programming tool that allows us to solve mathematical problems using built-in functions. We can take the partial derivative of the multivariate function in MATLAB using the built-in gradient() function with respect to one, two, or N variables. This guide has presented an easy guide with simple examples to take the partial derivative of a function in MATLAB.