Sum of the partial derivatives of a vector field >>> F = lambda x, y, z: (x*y+sin(x)+3*x, x-y-5*x, cos(2*x)-sin(y)**2) >>> divergence(F, (3.5, 2.1, -3.3)) 3.163543312709203 # http://www.wolframalpha.com/input/?i=div+%7Bx*y%2Bsin(x)%2B3*x,+x-y-5*x,+cos(2*x)-sin(y)%5
(F, point)
| 224 | return d(func(*map(Num, point, direction))) |
| 225 | |
| 226 | def divergence(F, point): |
| 227 | ''' Sum of the partial derivatives of a vector field |
| 228 | |
| 229 | >>> F = lambda x, y, z: (x*y+sin(x)+3*x, x-y-5*x, cos(2*x)-sin(y)**2) |
| 230 | >>> divergence(F, (3.5, 2.1, -3.3)) |
| 231 | 3.163543312709203 |
| 232 | |
| 233 | # http://www.wolframalpha.com/input/?i=div+%7Bx*y%2Bsin(x)%2B3*x,+x-y-5*x,+cos(2*x)-sin(y)%5E2%7D |
| 234 | >>> x, y, z = (3.5, 2.1, -3.3) |
| 235 | >>> math.cos(x) + y + 2 |
| 236 | 3.1635433127092036 |
| 237 | |
| 238 | >>> F = lambda x, y, z: (8 * exp(-x), cosh(z), - y**2) |
| 239 | >>> divergence(F, (2, -1, 4)) |
| 240 | -1.0826822658929016 |
| 241 | |
| 242 | # https://www.youtube.com/watch?v=S2rT2zK2bdo |
| 243 | >>> x, y, z = (2, -1, 4) |
| 244 | >>> -8 * math.exp(-x) |
| 245 | -1.0826822658929016 |
| 246 | |
| 247 | ''' |
| 248 | return math.fsum(d(F(*[Num(x, i==index) for i, x in enumerate(point)])[index]) |
| 249 | for index in range(len(point))) |
| 250 | |
| 251 | def curl(F, point): |
| 252 | ''' Rotation around a vector field |