I need to map vectors on a plane using Gradients.
I was given an equation and I then determined it's grad function (https://en.wikipedia.org/wiki/Gradient)
I now need to use python to map all the vectors on a plane
x and y are defined by the following :
-2<x<2 step = 0,25
-2<y<2 step = 0,25
So I started with this code : It can calculate the x and y components of the gradient vector. However I dont how to calculate the components (gradx and grady) for all the values of x and y.
import matplotlib.pyplot as plt
import numpy as np
from numpy import array
x = np.arange(-2,2,0.25)
y = np.arange(-2,2,0.25)
def gradx (x,y):
gradx = np.exp((-x^2)-(y^2))*(1-2*x^2+4*x^3-2*x^5)
return gradx
def grady (x,y):
grady = -2*np.exp(-x^2-y^2)*x*y*(1+x)*(1-x+x^2)
return grady
I then need to create vectors whose components are [gradx;grady] for every possible combination of x and y (there are a lot of them) and plot them.
I know I'm asking for quite a big project, if I could have some help for at least creating the vectors with the right components that would be very helpful.
question from:
https://stackoverflow.com/questions/65903807/create-gradient-vectors-in-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…