pythonplotstreamorbitcartesian-coordinates

Plotting flow field influenced by a simple circular orbit - hyperbolic attractor, given in polar coordinates, in Cartesian coordinate system - Python


I may have bitten more off than I can chew for a project and have to plot, as the title says, a flow field, or vector field as given in the example: The vector field I need to create, no need for the colours...

The dynamics of this system as given in the example with polar coordinates are: r' = 5 * r^2 * (1-r) and φ' = r

The system has a circular periodic orbit with radius 1 and is centered at the origin.The orbit is a hyperbolic attractor with B = R^2 \ {(0, 0)}. The period is T = 2π and the asymptotic phase is given exactly by θ(r, φ) = φ − 1/5r + 0.2.

As given on page 1511 of this PDF

Now, I've been googling something similar for days now, but can't seem to properly define the orbit, and all I seem to find is tutorials on planetary orbits or the Lorenz attractor. The best I've managed to come up with is this:

import numpy as np
import matplotlib.pyplot as plt

x, y = np.mgrid[2:-2:20j, 2:-2:20j]

r = np.sqrt(x**2 + y**2)
phi = np.arctan(y/x)

dr = 5*(r**2)*(1-r)
dphi = r

dx = (5*(r**2)*(1-r)*np.cos(phi)) - ((r**2)*np.sin(phi))
dy = (5*(r**2)*(1-r)*np.cos(phi)) + ((r**2)*np.sin(phi))

fig, ax = plt.subplots()
ax.quiver(x, y, dx, dy)
ax.set(aspect=1, title='NOT GOOD', xlabel='X', ylabel='Y')

plt.show()

Now, this returns a bad quiver plot, and I honestly don't know if I am even going the right direction. Would anyone care to explain how one would properly solve this so even a moron like me could understand? Please. Do I enter it as a function and do a streamplot of that, would I define it before or after converting from polar to Cartesian? Is my math even correct?


Solution

  • I think the rotation matrix to get the vector field in Cartesian coordinates was messed up:

    import numpy as np
    import matplotlib.pyplot as plt
    
    x, y = np.mgrid[2:-2:20j, 2:-2:20j]
    
    r = np.sqrt(x**2 + y**2)
    phi = np.arctan2(y, x)
    
    dr = 5*(r**2)*(1-r)
    dphi = r
    
    dx = dr*np.cos(phi) - dphi*np.sin(phi)
    dy = dr*np.sin(phi) + dphi*np.cos(phi)
    
    norm_dr = np.sqrt(dx**2 + dy**2)
    
    fig, ax = plt.subplots()
    ax.quiver(x, y, dx/norm_dr, dy/norm_dr)
    ax.set(aspect=1, title='GOOD?', xlabel='X', ylabel='Y')
    
    plt.show()
    

    the vectors are also normed in the plot, thus they all have the same size

    result graph