Help me on function definition

2008-03-28 Thread aeneng
Hello everyone,

I am just starting to use python in numerical cacluation. 
I need you to help me to see what's wrong with the following piece of 
codes, which computes the cross product of two vectors and returns 
the result. u and v are two 3x1 matrix.

when I import the function, error message show like this
>>> import cross
Traceback (most recent call last):
  File "", line 1, in ?
  File "cross.py", line 8
ppp2=u[2]*v[0]-u[0]*v[2]
^
SyntaxError: invalid syntax

WHAT IS WRONG WITH MY CODE?

I appreciate your help.

##here is the function definition.
##cross.py##
def cross(u,v)
"""input two vectors u and v in 3-D space, 
   output a cross product of vector w, in column or in row 
accordingly."""
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 cross(u,v)
print "file name is %s" %__name__ 


-- 
http://mail.python.org/mailman/listinfo/python-list


Error message from function definition

2008-03-28 Thread aeneng pan
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 "", 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)
-- 
http://mail.python.org/mailman/listinfo/python-list