From: Olivier Saut Date: 2012-09-09T16:33:32+09:00 Subject: Re: Using ruby for scientific computing Le 8 sept. 2012 à 23:31, Ryan Davis a écrit : > > On Sep 8, 2012, at 09:06 , Olivier Saut wrote: > >> Hi all, >> >> For pedagogic purposes, I am trying to solve simple partial differential >> equations (say a diffusion equation on a regular mesh in 2D) with Ruby. >> Using the NArray gem, I have built a satisfactory tool from an interface >> (and ease of use) point of view but the performance are suboptimal. > > Have you taken a look at std lib's matrix.rb? No, I'll check it. In particular there is a LU decomposition method implemented which could help me a lot. Thanks, > > = MMaattrriixx  <<  OObbjjeecctt > > (from ruby core) > ------------------------------------------------------------------------------ > The Matrix class represents a mathematical matrix, and provides methods for > creating special-case matrices (zero, identity, diagonal, singular, vector), > operating on them arithmetically and algebraically, and determining their > mathematical properties (trace, rank, inverse, determinant). > > Note that although matrices should theoretically be rectangular, this is not > enforced by the class. > > Also note that the determinant of integer matrices may be incorrectly > calculated unless you also require 'mathn'. This may be fixed in the future. > > == MMeetthhoodd  CCaattaalloogguuee > > To create a matrix: > * Matrix[*rows] > * Matrix.[](*rows) > * Matrix.rows(rows, copy = true) > * Matrix.columns(columns) > * Matrix.diagonal(*values) > * Matrix.scalar(n, value) > * Matrix.scalar(n, value) > * Matrix.identity(n) > * Matrix.unit(n) > * Matrix.I(n) > * Matrix.zero(n) > * Matrix.row_vector(row) > * Matrix.column_vector(column) > > To access Matrix elements/columns/rows/submatrices/properties: > * [](i, j) > * #row_size > * #column_size > * #row(i) > * #column(j) > * #collect > * #map > * #minor(*param) > > Properties of a matrix: > * #regular? > * #singular? > * #square? > > Matrix arithmetic: > * *(m) > * +(m) > * -(m) > * #/(m) > * #inverse > * #inv > * ** > > Matrix functions: > * #determinant > * #det > * #rank > * #trace > * #tr > * #transpose > * #t > > Conversion to other data types: > * #coerce(other) > * #row_vectors > * #column_vectors > * #to_a > > String representations: > * #to_s > * #inspect > ------------------------------------------------------------------------------ > = CCllaassss  mmeetthhooddss:: > > I > [] > column_vector > columns > diagonal > identity > new > row_vector > rows > scalar > unit > zero > > = IInnssttaannccee  mmeetthhooddss:: > > * > ** > + > - > / > == > [] > clone > coerce > collect > column > column_size > column_vectors > compare_by_row_vectors > det > determinant > eql? > hash > init_rows > inspect > inv > inverse > inverse_from > map > minor > rank > regular? > row > row_size > row_vectors > singular? > square? > t > to_a > to_s > tr > trace > transpose > - Olivier