Photon Light - 5 months ago 77

Python Question

I want to plot direction field for a simple equation:

`y' = 3 − 2y`

I have found similar Matlab problem here (1.3). But I do not know how to rewrite it to python. My last try is:

`from matplotlib.pyplot import cm`

import matplotlib.pyplot as plt

import numpy as np

nx, ny = .3, .3

x = np.arange(-3, 3, nx)

y = np.arange(-2, 2, ny)

X, Y = np.meshgrid(x, y)

dy = X + np.sin(Y)

dx = np.ones((10,10))

plot2 = plt.figure()

plt.quiver(X, Y, dx, dy,

color='Teal',

headlength=7)

plt.title('Quiver Plot, Single Colour')

plt.show(plot2)

But I'm getting error:

`builtins.ValueError: operands could not be broadcast together with shapes (100,) (280,)`

I though it will be very simple, but after few hours of searching how to plot a simple direction field, I am quite depressed.

Answer