MCPcopy Create free account
hub / github.com/ActiveState/code / curl

Function curl

recipes/Python/580610_Auto_differentiation/recipe-580610.py:251–282  ·  view source on GitHub ↗

Rotation around a vector field >>> F = lambda x, y, z: (x*y+sin(x)+3*x, x-y-5*x, cos(2*x)-sin(y)**2) >>> curl(F, (3.5, 2.1, -3.3)) (0.8715757724135881, 1.3139731974375781, -7.5) # http://www.wolframalpha.com/input/?i=curl+%7Bx*y%2Bsin(x)%2B3*x,+x-y-5*x,+cos(2*x)-si

(F, point)

Source from the content-addressed store, hash-verified

249 for index in range(len(point)))
250
251def curl(F, point):
252 ''' Rotation around a vector field
253
254 >>> F = lambda x, y, z: (x*y+sin(x)+3*x, x-y-5*x, cos(2*x)-sin(y)**2)
255 >>> curl(F, (3.5, 2.1, -3.3))
256 (0.8715757724135881, 1.3139731974375781, -7.5)
257
258 # http://www.wolframalpha.com/input/?i=curl+%7Bx*y%2Bsin(x)%2B3*x,+x-y-5*x,+cos(2*x)-sin(y)%5E2%7D
259 >>> x, y, z = (3.5, 2.1, -3.3)
260 >>> (-2 * math.sin(y) * math.cos(y), 2 * math.sin(2 * x), -x - 4)
261 (0.8715757724135881, 1.3139731974375781, -7.5)
262
263 # https://www.youtube.com/watch?v=UW4SQz29TDc
264 >>> F = lambda x, y, z: (y**4 - x**2 * z**2, x**2 + y**2, -x**2 * y * z)
265 >>> curl(F, (1, 3, -2))
266 (2.0, -8.0, -106.0)
267
268 >>> F = lambda x, y, z: (8 * exp(-x), cosh(z), - y**2)
269 >>> curl(F, (2, -1, 4))
270 (-25.289917197127753, 0.0, 0.0)
271
272 # https://www.youtube.com/watch?v=S2rT2zK2bdo
273 >>> x, y, z = (2, -1, 4)
274 >>> (-(x * y + math.sinh(z)), 0.0, 0.0)
275 (-25.289917197127753, 0.0, 0.0)
276
277 '''
278 x, y, z = point
279 _, Fyx, Fzx = map(d, F(Var(x), y, z))
280 Fxy, _, Fzy = map(d, F(x, Var(y), z))
281 Fxz, Fyz, _ = map(d, F(x, y, Var(z)))
282 return (Fzy - Fyz, Fxz - Fzx, Fyx - Fxy)
283
284
285if __name__ == '__main__':

Callers 1

recipe-580610.pyFile · 0.85

Calls 3

mapFunction · 0.85
FFunction · 0.50
VarClass · 0.50

Tested by

no test coverage detected