0

I have this python script to generate x,y,z lists and u,v,w lists such that u[i],v[i],w[i] is the gradient vector for point x[i],y[i],z[i].

It doesn't seem to be getting the right values. Does anyone know whats wrong?

from math import *

def coordinates(lst, f, gradx, grady, gradz):

    lst = lst[1:-1].split(",")
    lst = [float(x.strip()) for x in lst]

    xlst = []
    ylst = []
    zlst = []
    ulst = []
    vlst = []
    wlst = []

    for x in lst:
        for y in lst:
            xlst.append(str(x))
            ylst.append(str(y))
            zlst.append(str(f(x,y)))
            ulst.append(str(gradx(x,y)))
            vlst.append(str(grady(x,y)))
            wlst.append(str(gradz(x,y)))

    string = "xlst=[" + ",".join(xlst) + "]\n" + \
    "ylst=[" + ",".join(ylst) + "]\n" + \
    "zlst=[" + ",".join(zlst) + "]\n" + \
    "ulst=[" + ",".join(ulst) + "]\n" + \
    "vlst=[" + ",".join(vlst) + "]\n" + \
    "wlst=[" + ",".join(wlst) + "]\n"



    return string

lst = "{0, 2, 4, 6, 8, 10}"

# get function in the form f(x,y)=z  or  here its y^2 - x^2 - z = 0
f = lambda x,y: y**2 - x**2
# get the three gradient functions (df/dx, df/dy, df/dz)
gx = lambda x,y: -2*x
gy = lambda x,y: 2*y
gz = lambda x,y: -1

c = coordinates(lst, f, gx, gy, gz)
print c
omega
  • 40,311
  • 81
  • 251
  • 474
  • 1
    "doesn't seem to be getting the right values": could you be more specific? – Scott Hunter Apr 04 '14 at 19:58
  • Please give sample input, actual output and expected output. – Hyperboreus Apr 04 '14 at 20:09
  • are all the parameters in the calls to gradx, grady, gradz right? – jcfollower Apr 04 '14 at 20:37
  • It looks like this correctly gives the **Normal** to the surface. It will not be scaled to unit length which might be a problem. Its not quite clear what you mean by gradient vector. Do you meant a Normal or Tangent vectors? Many vectors are tangent to the surface. – Salix alba Apr 05 '14 at 08:50

0 Answers0