```python
%pylab inline
```

    Populating the interactive namespace from numpy and matplotlib



```python
from sympy import symbols
import numpy as np
```


```python
f = lambda x, y: x * y
```


```python
def find_gradient_2d(f):
        x, y = symbols('x y')
        f = f(x, y)
        df_dx = f.diff(x)
        df_dy = f.diff(y)
        return np.array([df_dx, df_dy])
```


```python
def eval_gradient_2d(grad, p):
    x = grad[0].subs('x', p[0]).subs('y', p[1])
    y = grad[1].subs('x', p[0]).subs('y', p[1])
    return np.array([x.evalf(), y.evalf()])
```


```python
def find_directional_deriv(grad, direction):
    x = grad[0] * direction[0]
    y = grad[1] * direction[1]
    return np.array([x, y])
```


```python
def eval_directional_deriv(dir_deriv, p):
    x = dir_deriv[0].subs('x', p[0]).subs('y', p[1])
    y = dir_deriv[1].subs('x', p[0]).subs('y', p[1])
    return np.array([x.evalf(), y.evalf()])
```


```python
grad = find_gradient_2d(f)
direction = np.array([1,0])
dir_deriv = find_directional_deriv(grad, direction)
dir_deriv
```




    array([y, 0], dtype=object)




```python
eval_gradient_2d(grad, [1,1])
```




    array([1.00000000000000, 1.00000000000000], dtype=object)




```python
X, Y = np.meshgrid(np.arange(1, 10, 0.25), np.arange(1, 10, 0.25))
G = [eval_gradient_2d(grad, [x, y]) for x in X for y in Y]
print(G)
U = [g[0] for g in G]
V = [g[1] for g in G]
print(U,V)

fig, ax = plt.subplots(figsize=(12,12))
q = ax.quiver(X, Y, U, V)
ax.quiverkey(q, X=0.3, Y=1.1, U=10, label='Quiver key, length = 10', labelpos='E')
```


```python

```


```python

```

05a075571719a9faaadee2e24d95aeb3305d7e56
ipynb
Jupyter Notebook
Applied Math/Y2S2/.ipynb_checkpoints/Gradients & Directional Derivatives-checkpoint.ipynb
darkeclipz/jupyter-notebooks
5de784244ad9db12cfacbbec3053b11f10456d7e
Unlicense
2018-08-28T12:16:12.000Z
2018-08-28T12:16:12.000Z
Applied Math/Y2S2/Gradients & Directional Derivatives.ipynb
darkeclipz/jupyter-notebooks
5de784244ad9db12cfacbbec3053b11f10456d7e
Unlicense
Applied Math/Y2S2/Gradients & Directional Derivatives.ipynb
darkeclipz/jupyter-notebooks
5de784244ad9db12cfacbbec3053b11f10456d7e
Unlicense
Qwen/Qwen-72B
1. YES
2. YES