```python
from sympy import *
init_printing(use_latex='mathjax')
```


```python
def get_diff(expressions, symbols):
    rows = len(expressions)
    columns = len(symbols)
    assert rows == columns , "Number of expression doesnt match number of symbols"
    
    print("Expressions:")
    for expression in expressions:
        display(expression)

    results = [[0 for x in range(rows)] for y in range(columns)] 
    for row, expression in enumerate(expressions):
        for column, symbol in enumerate(symbols):
#             print('Row %d, column %d, expression: %s, symbol: %s' % (row, column, expression, symbol))
            df = diff(expression, symbol)
#             print("DF: %s" % df)
            results[row][column] = df
    return results
```


```python
x, y = symbols('x y')
get_diff([x ** 2 - y**2, 2 * x * y], [x, y])
```

    Expressions:



$$x^{2} - y^{2}$$



$$2 x y$$





$$\left [ \left [ 2 x, \quad - 2 y\right ], \quad \left [ 2 y, \quad 2 x\right ]\right ]$$




```python
x, y, z = symbols('x y z')
get_diff([
    2 * x + 3 * y,
    cos(x) * sin(z),
    exp(x) * exp(y) * exp(z)
], [x, y , z])
```

    Expressions:



$$2 x + 3 y$$



$$\sin{\left (z \right )} \cos{\left (x \right )}$$



$$e^{x} e^{y} e^{z}$$





$$\left [ \left [ 2, \quad 3, \quad 0\right ], \quad \left [ - \sin{\left (x \right )} \sin{\left (z \right )}, \quad 0, \quad \cos{\left (x \right )} \cos{\left (z \right )}\right ], \quad \left [ e^{x} e^{y} e^{z}, \quad e^{x} e^{y} e^{z}, \quad e^{x} e^{y} e^{z}\right ]\right ]$$




```python
x, y, a, b, c, d = symbols('x y a b c d')
get_diff([
    a * x + b * y,
    c * x + d * y
], [x, y])
```

    Expressions:



$$a x + b y$$



$$c x + d y$$





$$\left [ \left [ a, \quad b\right ], \quad \left [ c, \quad d\right ]\right ]$$




```python
def jacobian_at(jacobian, point):
    rows = len(jacobian)
    columns = len(jacobian[0])
    results = [[0 for x in range(rows)] for y in range(columns)] 
    for rowIndex, row in enumerate(jacobian):
        for colIndex, cell in enumerate(row):
            results[rowIndex][colIndex] = cell.evalf(subs=point)
            
    return results
```


```python
x, y, z = symbols('x y z')
J = get_diff([
    9 * x ** 2 * y ** 2 + z * exp(x),
    x * y + x ** 2 * y ** 3 + 2 * z,
    cos(x) * sin(z) * exp(y)
], [x, y, z])
jacobian_at(J, {x: 0, y:0, z:0})
```

    Expressions:



$$9 x^{2} y^{2} + z e^{x}$$



$$x^{2} y^{3} + x y + 2 z$$



$$e^{y} \sin{\left (z \right )} \cos{\left (x \right )}$$





$$\left [ \left [ 0, \quad 0, \quad 1.0\right ], \quad \left [ 0, \quad 0, \quad 2.0\right ], \quad \left [ 0, \quad 0, \quad 1.0\right ]\right ]$$




```python
r, theta, phi = symbols('r theta phi')
get_diff([
    r * cos(theta) * sin(phi),
    r * sin(theta) * sin(phi),
    r * cos(phi)
], [r, theta, phi])
```

    Expressions:



$$r \sin{\left (\phi \right )} \cos{\left (\theta \right )}$$



$$r \sin{\left (\phi \right )} \sin{\left (\theta \right )}$$



$$r \cos{\left (\phi \right )}$$





$$\left [ \left [ \sin{\left (\phi \right )} \cos{\left (\theta \right )}, \quad - r \sin{\left (\phi \right )} \sin{\left (\theta \right )}, \quad r \cos{\left (\phi \right )} \cos{\left (\theta \right )}\right ], \quad \left [ \sin{\left (\phi \right )} \sin{\left (\theta \right )}, \quad r \sin{\left (\phi \right )} \cos{\left (\theta \right )}, \quad r \sin{\left (\theta \right )} \cos{\left (\phi \right )}\right ], \quad \left [ \cos{\left (\phi \right )}, \quad 0, \quad - r \sin{\left (\phi \right )}\right ]\right ]$$




```python

```

1864aaf237c6ea7f42ad859290d5de2ca4bb3e2d
ipynb
Jupyter Notebook
Certification 2/Week2.3 - Jacobian Matrix.ipynb
The-Brains/MathForMachineLearning
5cbd9006f166059efaa2f312b741e64ce584aa1f
MIT
2018-04-16T02:53:59.000Z
2021-05-16T06:51:57.000Z
Certification 2/Week2.3 - Jacobian Matrix.ipynb
The-Brains/MathForMachineLearning
5cbd9006f166059efaa2f312b741e64ce584aa1f
MIT
Certification 2/Week2.3 - Jacobian Matrix.ipynb
The-Brains/MathForMachineLearning
5cbd9006f166059efaa2f312b741e64ce584aa1f
MIT
2019-05-20T02:06:55.000Z
2020-05-18T06:21:41.000Z
Qwen/Qwen-72B
1. YES
2. YES