Solving an equation in Python [closed]
i'm trying to solve an equation but I don't know the way to do this. I've got a vector x wich is actually a matrix type and I would like to solve the equation x.transpose()*v=0 where v is another vector
Can someone help me?
I thank you in advance
Take any vector at all and project it into the orthogonal complement of x
.
Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> x = numpy.matrix([1, 3.14, 2.73]).T
>>> P = x * x.T / (x.T * x) # projector onto the space spanned by x
>>> Pperp = numpy.identity(3) - P # projector onto x's orthogonal complement
>>> Pperp * x
matrix([[ 0.00000000e+00],
[ 0.00000000e+00],
[ -2.22044605e-16]])
>>> y = numpy.matrix(numpy.ones((3,1)))
>>> yperp = Pperp * y
>>> yperp
matrix([[ 0.62484642],
[-0.17798225],
[-0.02416928]])
>>> x.T * yperp
matrix([[ -4.16333634e-16]])
As written, this is quite unrestrained and gives a fairly arbitrary solution, but the same idea can be built up to find a set of basis vectors for all solutions.
x.T*v
is another way of writing the dot product between vectors x
and v
, so it sounds like you want to find a vector v
which is orthogonal to x
. For the general case, there are infinitely many solutions (in 3 dimensions, imagine any vector v
in the plane perpendicular to x).
You have said in your comment you know there are a lot of possible solutions, and how can you get one, so here is one for you:
v = 0
精彩评论