Very quick and dirty question. I'm trying to write a program written in python into mathematica and there is a section that uses the gradient function in the numpty python library, np.gradient (https://numpy.org/doc/stable/reference/generated/numpy.gradient.html). In the python script it just finds the gradient of a list of numbers.
Is there a Mathematica equivalent? I see there is a Grad function but it seems to be used for functions rather than a list of numbers, or I just don't know how to use it.
Here's the python script snippet, v is a list of numbers, so is z_list as are all the betas, int_phi is a function that uses the betas to produce, you guessed it, a list of numbers. Also in python, you have to split functions up into real and imaginary to integrate them, that's one point to mathematica I guess lol
for j in range(len(v)):
print(j)
phi_r = np.empty(len(z_list))
phi_i = np.empty(len(z_list))
for i in range(len(z_list)):
z = z_list[i]
b_21=beta21[j]
b_12=beta12[j] #dunne schicht mos2 grenzt an luft
b_23=beta23[j] #intercal mos2 grem-nzt an mos2
a = quad(lambda q: np.real(int_phi(q,z)), 0, np.inf)[0] (* integrate over pre-
defined function 0->inf*)
phi_r[i] = a
a = quad(lambda q: np.imag(int_phi(q,z)), 0, np.inf)[0]
phi_i[i] = a
#calculate derivatives
phi_r_ = np.gradient(phi_r,z_list)
phi_i_ = np.gradient(phi_i,z_list)
Any help would be greatly appreciated, thank you!
Thank you sir/ma'am
– Koji Oct 07 '22 at 09:34