# jacobian

Jacobian matrix

## Description

example

jacobian(f,v) computes the Jacobian matrix of f with respect to v. The (i,j) element of the result is $\frac{\partial f\left(i\right)}{\partial \text{v}\left(j\right)}$.

## Examples

collapse all

The Jacobian of a vector function is a matrix of the partial derivatives of that function.

Compute the Jacobian matrix of [x*y*z,y^2,x + z] with respect to [x,y,z].

syms x y z
jacobian([x*y*z,y^2,x + z],[x,y,z])
ans =

$\left(\begin{array}{ccc}y z& x z& x y\\ 0& 2 y& 0\\ 1& 0& 1\end{array}\right)$

Now, compute the Jacobian of [x*y*z,y^2,x + z] with respect to [x;y;z].

jacobian([x*y*z,y^2,x + z], [x;y;z])
ans =

$\left(\begin{array}{ccc}y z& x z& x y\\ 0& 2 y& 0\\ 1& 0& 1\end{array}\right)$

The Jacobian matrix is invariant to the orientation of the vector in the second input position.

The Jacobian of a scalar function is the transpose of its gradient.

Compute the Jacobian of 2*x + 3*y + 4*z with respect to [x,y,z].

syms x y z
jacobian(2*x + 3*y + 4*z,[x,y,z])
ans = $\left(\begin{array}{ccc}2& 3& 4\end{array}\right)$

Now, compute the gradient of the same expression.

ans =

$\left(\begin{array}{c}2\\ 3\\ 4\end{array}\right)$

The Jacobian of a function with respect to a scalar is the first derivative of that function. For a vector function, the Jacobian with respect to a scalar is a vector of the first derivatives.

Compute the Jacobian of [x^2*y,x*sin(y)] with respect to x.

syms x y
jacobian([x^2*y,x*sin(y)],x)
ans =

$\left(\begin{array}{c}2 x y\\ \mathrm{sin}\left(y\right)\end{array}\right)$

Now, compute the derivatives.

diff([x^2*y,x*sin(y)],x)
ans = $\left(\begin{array}{cc}2 x y& \mathrm{sin}\left(y\right)\end{array}\right)$

Specify polar coordinates $r\left(t\right)$, $\varphi \left(t\right)$, and $\theta \left(t\right)$ that are functions of time.

syms r(t) phi(t) theta(t)

Define the coordinate transformation form spherical coordinates to Cartesian coordinates.

R = [r*sin(phi)*cos(theta), r*sin(phi)*sin(theta), r*cos(phi)]
R(t) = $\left(\begin{array}{ccc}\mathrm{cos}\left(\theta \left(t\right)\right) \mathrm{sin}\left(\varphi \left(t\right)\right) r\left(t\right)& \mathrm{sin}\left(\varphi \left(t\right)\right) \mathrm{sin}\left(\theta \left(t\right)\right) r\left(t\right)& \mathrm{cos}\left(\varphi \left(t\right)\right) r\left(t\right)\end{array}\right)$

Find the Jacobian of the coordinate change from spherical coordinates to Cartesian coordinates.

jacobian(R,[r,phi,theta])
ans(t) =

$\left(\begin{array}{ccc}\mathrm{cos}\left(\theta \left(t\right)\right) \mathrm{sin}\left(\varphi \left(t\right)\right)& \mathrm{cos}\left(\varphi \left(t\right)\right) \mathrm{cos}\left(\theta \left(t\right)\right) r\left(t\right)& -\mathrm{sin}\left(\varphi \left(t\right)\right) \mathrm{sin}\left(\theta \left(t\right)\right) r\left(t\right)\\ \mathrm{sin}\left(\varphi \left(t\right)\right) \mathrm{sin}\left(\theta \left(t\right)\right)& \mathrm{cos}\left(\varphi \left(t\right)\right) \mathrm{sin}\left(\theta \left(t\right)\right) r\left(t\right)& \mathrm{cos}\left(\theta \left(t\right)\right) \mathrm{sin}\left(\varphi \left(t\right)\right) r\left(t\right)\\ \mathrm{cos}\left(\varphi \left(t\right)\right)& -\mathrm{sin}\left(\varphi \left(t\right)\right) r\left(t\right)& 0\end{array}\right)$

## Input Arguments

collapse all

Scalar or vector function, specified as a symbolic expression, function, or vector. If f is a scalar, then the Jacobian matrix of f is the transposed gradient of f.

Vector of variables or functions with respect to which you compute Jacobian, specified as a symbolic variable, symbolic function, or vector of symbolic variables. If v is a scalar, then the result is equal to the transpose of diff(f,v). If v is an empty symbolic object, such as sym([]), then jacobian returns an empty symbolic object.

collapse all

### Jacobian Matrix

The Jacobian matrix of the vector function f = (f1(x1,...,xn),...,fn(x1,...,xn)) is the matrix of the derivatives of f:

$J\left({x}_{1},\dots {x}_{n}\right)=\left[\begin{array}{ccc}\frac{\partial {f}_{1}}{\partial {x}_{1}}& \cdots & \frac{\partial {f}_{1}}{\partial {x}_{n}}\\ ⋮& \ddots & ⋮\\ \frac{\partial {f}_{n}}{\partial {x}_{1}}& \cdots & \frac{\partial {f}_{n}}{\partial {x}_{n}}\end{array}\right]$

## Version History

Introduced before R2006a