Linear system solver in D?

Guillaume B. guillaume.b.spam at sympatico.ca
Tue Feb 19 17:27:31 PST 2008


Bill Baxter wrote:

> Guillaume B. wrote:
>> BCS wrote:
>> 
>>> Bill Baxter wrote:
>>>> Christopher Wright wrote:
>>>>
>>>>> BCS wrote:
>>>>>
>>>>>> I am going to have a system of equations like this
>>>>>>
>>>>>> a_11*x_1 + a_12*x2 + ... a_1n*x_n = y_1
>>>>>> a_21*x_1 + a_22*x2 + ... a_2n*x_n = y_2
>>>>>> ..
>>>>>> ..
>>>>>> ..
>>>>>> a_m1*x_1 + a_m2*x2 + ... a_mn*x_n = y_m
>>>>>>
>>>>>> y_* and a_* known, I need to find x_*
>>>>>>
>>>>>> What is the best available solver for such a system that works under
>>>>>> D?
>>>>>>
>>>>>> C bindings would work, D code would be better and I'd rather stay
>>>>>> away from non portable (uses __ asm and has no port to other system).
>>>>>>
>>>>>> If no one knows of a good lib that is ready to use, what is a good C
>>>>>> lib to do bindings for?
>>>>>>
>>>>>>
>>>>>> p.s. I'm going to be putting this in a non-linear root finder, has
>>>>>> someone already written on of those for D.
>>>>>
>>>>> You definitely want bindings rather than native D. D just hasn't been
>>>>> around long enough for people to make decent math libraries for it;
>>>>> most of the people with the required skills are still transitioning
>>>>> from Fortran.
>>>>>
>>>>> You could use GLPK -- it's a linear solver that accepts a superset of
>>>>> AMPL. If you're doing serious work on large data sets, go with CPLEX.
>>>>> If you manage to write something that does any better than GLPK, start
>>>>> a company. CPLEX is significantly better, but you might be able to
>>>>> make some money if you marketed it toward smaller research projects
>>>>> for $500 or so.
>>>>
>>>> Multiarray has bindings to LAPACK.
>>>>
>>>> http://www.dsource.org/projects/multiarray
>>>>
>>>> There are bindings for GSL which I think uses LAPACK also somewhere on
>>>> dsource (either its own project or maybe it was in the 'bindings'
>>>> project).
>>>>
>>>> I'm working on a new d library that will wrap LAPACK and some sparse
>>>> lib
>>>> like SuperLU and/or TAUCS.  The new lib is based loosely on FLENS.
>>>>
>>>> --bb
>>> thanks, both or you, I'll look at those. Performance isn't that big an
>>> issue as I'm only looking at about 15-30 equations and a few minutes run
>>> time would be ok, but I'm going to have to run ~1500 passes through it.
>> 
>> 
>>  lp_solve is nice too: http://lpsolve.sourceforge.net/5.5/ ... and it can
>> read many file formats...
> 
> Hmm, I was assuming he was after D code.  If not, for instance if you
> just have some equations you want to solve, then I'd just write a short
> python/numpy script:
> ---
> from numpy import *
> A = asarray([[a_11, a_12 ...],
>               [a_21, a_22 ...],
>               ...
>               [a_m1, a_m2 ...]])
> y = asarray([y_1, y_2...])
> x = lstsq(A,y)[0]
> ---
> 
> Voila

 Well, lp_solve is in C so the bindings should be fairly easy to write... I
suggested that since others suggested using bindings to existing libraries.

 Guillaume



More information about the Digitalmars-d-learn mailing list