Loading...
Searching...
No Matches
plotNonconservative.py
1#!/usr/bin/env python3
2
3
36
37# Authors: Caleb Voss, Wilson Beebe
38
39import matplotlib.pyplot as plt
40from pylab import meshgrid, arange, quiver, quiverkey, sqrt
41import numpy as np
42
43
44def makeVectorField(f, xmin, xmax, ymin, ymax, step):
45 X, Y = meshgrid(arange(xmin, xmax, step), arange(ymin, ymax, step))
46 U, V = zip(*map(lambda xx: f(*xx), zip(X, Y)))
47 Q = quiver(X, Y, U, V, units="width")
48 quiverkey(Q, 0, 0, 4, "", coordinates="figure", labelpos="W")
49
50
51fig = plt.figure()
52ax = fig.gca(aspect="equal")
53x = np.loadtxt("vfrrt-nonconservative.path")
54makeVectorField(
55 lambda x, y: (y / sqrt(x * x + y * y + 1e-6), -x / sqrt(x * x + y * y + 1e-6)),
56 -6,
57 6,
58 -6,
59 6,
60 0.5,
61)
62ax.plot(x[:, 0], x[:, 1])
63plt.show()