Vector fields

2001 days ago by JAVIER

import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D 
       
x = y = np.linspace(1,10,11) fx = np.sin(x) fy = np.cos(y) A = np.array([fx,fy]).T print A #print A.T 
       
[[ 0.84147098  0.54030231]
 [ 0.94630009 -0.32328957]
 [ 0.33498815 -0.94222234]
 [-0.52983614 -0.84810003]
 [-0.993691   -0.11215253]
 [-0.70554033  0.70866977]
 [ 0.1165492   0.99318492]
 [ 0.85043662  0.52607752]
 [ 0.94073056 -0.33915486]
 [ 0.31909836 -0.9477216 ]
 [-0.54402111 -0.83907153]]
[[ 0.84147098  0.54030231]
 [ 0.94630009 -0.32328957]
 [ 0.33498815 -0.94222234]
 [-0.52983614 -0.84810003]
 [-0.993691   -0.11215253]
 [-0.70554033  0.70866977]
 [ 0.1165492   0.99318492]
 [ 0.85043662  0.52607752]
 [ 0.94073056 -0.33915486]
 [ 0.31909836 -0.9477216 ]
 [-0.54402111 -0.83907153]]
def vector_field(x,y): f_x = -y*0.1 f_y = x*0.1 return f_x,f_y #return np.array([f_x,f_y]).T 
       
fig = plt.figure() axes = fig.add_subplot(111) N = 20 L = 10 F = 1.5 xx = np.linspace(-L,L,N) yy = np.linspace(-L,L,N) X,Y = np.meshgrid(xx,yy) for x,y in zip(np.ravel(X),np.ravel(Y)): #print x,y fx,fy = vector_field(x,y) #print fx,fy axes.arrow(x, y, fx, fy, head_width=0.05*L, head_length=0.05*L, fc='k', ec='k') axes.set_xlim([-F*L,F*L]) axes.set_ylim([-F*L,F*L]) fig.savefig('test.png') plt.cla() 
       
def vector_field(x,y): f_x = sin(y)*1 f_y = cos(x)*1 return f_x,f_y #return np.array([f_x,f_y]).T 
       
fig2 = plt.figure() axes2 = fig2.add_subplot(111) N = 25 L = 10 F = 1.5 xx = np.linspace(-L,L,N) yy = np.linspace(-L,L,N) X,Y = np.meshgrid(xx,yy) for x,y in zip(np.ravel(X),np.ravel(Y)): #print x,y fx,fy = vector_field(x,y) #print fx,fy axes2.arrow(x, y, fx, fy, head_width=0.05*L, head_length=0.05*L, fc='k', ec='k') axes2.set_xlim([-F*L,F*L]) axes2.set_ylim([-F*L,F*L]) fig2.savefig('test.png') plt.cla()