Error message from function definition
aeneng pan
aeneng at gmail.com
Sat Mar 29 03:10:10 CET 2008
Dear community members,
I just start to use python in numerical calculation. and I encountered some
difficulties when I define my own function.
Here is a piece of codes to compute the cross product of two 3x1 vector.
can any one help me to find what is wrong with it? please see the codes
below.
when I import this function, it is not correct. here is the message I got.
>>> import cross
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "cross.py", line 8
ppp2=u[2]*v[0]-u[0]*v[2]
^
SyntaxError: invalid syntax
Thank you very much.
Neng
##cross.py##
def cross(u,v):
"""input two vectors u and v in 3-D space, both are in column or are in
row.
output a cross product of vector w, in column or in row accordingly.
w=u x v. The type of u, v, w are matrix type from optcvx.base.matrix."""
ppp1,ppp2,ppp3=0.0,0.0,0.0
ppp1=u[1]*v[2]-u[2]*v[1]
ppp2=u[2]*v[0]-u[0]*v[2]
ppp3=u[0]*v[1]-u[1]*v[0]
# store the result of the cross product in u
u[0]=ppp1
u[1]=ppp2
u[2]=ppp3
return u #return the cross product of vector u x v.
if __name__=="__main__":
from cvxopt.base import matrix
u=matrix([1.0,0.0,0.0],(3,1))
v=matrix([0.0,1.0,0.0],(3,1))
print "the cross product, uxv, is w= %6.3f" % cross(u,v)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080328/9e9b19fc/attachment.html>
More information about the Python-list
mailing list