Re: solving equation system



On 2006-07-17, TG <girodt@xxxxxxxxx> wrote:

Ben C wrote:
On 2006-07-17, TG <girodt@xxxxxxxxx> wrote:
Hi there.

Anyone knows how to use numpy / scipy in order to solve this ?

* A is an array of shape (n,)
* X is a positive float number
* B is an array of shape (n,)
* O is an array of shape (n,) containing only zeros.

A.X - B = O
min(X)

Are we solving for A, B or X? And what do you mean by min(X)?

If we're solving for X there will be many combinations of A and B for
which there is no solution.

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

How about this:

from random import *

def solve(A, B):
return reduce(max, (float(b) / a for a, b in zip(A, B)))

def test():
A = [random() for i in range(4)]
B = [random() for i in range(4)]

x = solve(A, B)

for a, b in zip(A, B):
print a, b, a * x - b

test()

This only works if all elements of both A and B are positive.

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.

Is this an array of points, or an array of values, that contains only
one point?

- 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

Do you mean the vector L - W? (LW is a scalar, assuming dot product).

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'm not sure this is clear ... pretty hard to talk about maths in
english.

Not very clear to me I'm afraid!
.



Relevant Pages

  • [SUMMARY] Records and Arrays (#170)
    ... quiz problem isn't necessary. ... or gets initialized to an empty array. ... important since we can refer to the original data. ... def initialize ...
    (comp.lang.ruby)
  • [SUMMARY] DayRange (#92)
    ... A couple of submitters mentioned that this problem isn't quite as simple as it ... def test_english ... This is the heart of the String building process and many solutions landed on ... Array of Arrays with the days divided into groups of start and end days. ...
    (comp.lang.ruby)
  • Re: Special characters and superscripts in PostScript and EPS
    ... When does one use bind def and load def? ... what you actually are doing is creating an executable array on the stack ... When you execute the array, if it contains any names the interpreter ... The 'load' operator searches dictionaries looking for a named value. ...
    (comp.lang.postscript)
  • [SUMMARY] One-Liners Mashup (#177)
    ... Thanks to everyone who joined in on the one-liners mashup. ... def repeat ... Sort an array of words by the words' values where a word's value is the ... matches regexp with two preceding and two successional lines. ...
    (comp.lang.ruby)
  • [QUIZ][SOLUTION] Getting to 100 (#119)
    ... to generate all permutations of an Array, but excluding those that are the ... Ops can have arbitrary effects on the Array, ... # Yield once for each unique element of this Array. ... def each_uniq_element ...
    (comp.lang.ruby)