Vector of the partial derivatives of a scalar field >>> func = lambda x, y: x*y + sin(x) >>> point = (2.5, 3.5) >>> gradient(func, point) (2.6988563844530664, 2.5) See: https://www.wolframalpha.com/input/?lk=3&i=grad(x*y+%2B+sin(x))
(func, point)
| 192 | return d(func(*[Num(x, i==index) for i, x in enumerate(point)])) |
| 193 | |
| 194 | def gradient(func, point): |
| 195 | ''' Vector of the partial derivatives of a scalar field |
| 196 | |
| 197 | >>> func = lambda x, y: x*y + sin(x) |
| 198 | >>> point = (2.5, 3.5) |
| 199 | >>> gradient(func, point) |
| 200 | (2.6988563844530664, 2.5) |
| 201 | |
| 202 | See: https://www.wolframalpha.com/input/?lk=3&i=grad(x*y+%2B+sin(x)) |
| 203 | |
| 204 | ''' |
| 205 | return tuple(partial(func, point, index) for index in range(len(point))) |
| 206 | |
| 207 | def directional_derivative(func, point, direction): |
| 208 | ''' The dot product of the gradient and a direction vector. |