solving equation system

Carl Banks pavlovevidence at gmail.com
Mon Jul 17 21:16:52 EDT 2006


TG wrote:
> Sorry for the poor explanation. I'm trying to put it clear now.
>
> i've got A and B. I'm looking for X. I made a mistake in my equation
> :-/
>
> It's more like :
>
> A.X - B >= O
>
> Well, maybe it will be much more simple if I explain the underlying
> problem :
>
> I have an array of N dimensions (generally 2).
> - A first calculation gives me a set of integer coordinates inside this
> array, which I will call the point W.
> - After several other calculations, I've got a set of coordinates in
> this N dimensional space that are floating values, and not bound to the
> limits of my original N-array. This is the point L.
>
> What I want to do is to translate the point L along the vector LW in
> order to get a point L' which coordinates are inside the original
> N-dimensional array. Then it will be easy to get the closest integer
> coordinates from L'.

I see.  You have a simple linear programming problem.  These can be
tricky in general.  Because you only have one variable, it's probably
ok to use brute force.  Try this:

given X, A, and B:

E = A*X-B
C = numpy.where(E<0,B/A,X)
X = min(C)

This assumes that you've designed the problem such that B/A would be
less than X where A*X-B<0 (if the opposite were true then of course
you'd need max(C)).


Carl Banks




More information about the Python-list mailing list