My personal opinion (just 2p worth) is that it's not appropriate for
the core Array class since it's only applicable to a particular sort
of array. The Matrix class add-on does include matrix multiplication
etc, makes more sense there.
By the way, instead of "if( this.flop.size == matrix.size)" use "if(
this[0].size == matrix.size)". Why? Because .flop is pretty heavy duty
for big matrices, so worth avoiding...
Dan
2008/5/12 Miguel Negrao <
miguel.negrao@...>:
> Thanks, that's simpler than the code i was working on. Maybe something
> like this could be added to Array ?
>
> //this assumes array elements are rows of a matrix
> + Array {
>
> mult { |matrix|
>
> if( this.flop.size == matrix.size)
> { ^ this.collect{|row| (row * matrix).sum } }
> { "Error: matrix dimensions mismatch".postln;
> ^nil
> }
>
> }
> }
>
> Miguel
>
> Dan Stowell escreveu:
>
>
> > Yes, I haven't used that class either but you may find it useful.
> >
> > In fact matrix multiplication can be written fairly compactly in plain SC:
> >
> > a = [[1, 0, 2], [-1, 3, 1]];
> > b = [[3,1], [2,1], [1,0]];
> >
> > a.collect{|row| (row * b).sum }
> >
> > Dan
> >
> > 2008/5/12 Luke Selden <
lselden@...>:
> >> In the MathLib Quark there's a Matrix class that I haven't used but
> >> might be worth looking into.
> >>
> >> ~luke
> >>
> >>
> >>
> >> On Mon, May 12, 2008 at 7:26 AM, Miguel Negrao
> >> <
miguel.negrao@...> wrote:
> >> > Hi
> >> >
> >> > Is there a way to do linear algebra in sc, specifically matrix
> >> > multiplication (matrix with matrix, matrix with vector,etc) ?
> >> >
> >> > thanks
> >> > Miguel Negrão
> >> > _______________________________________________
> >> > sc-users mailing list
> >> >
sc-users@...
> >> >
http://lists.create.ucsb.edu/mailman/listinfo/sc-users> >> >
> >> _______________________________________________
> >> sc-users mailing list
> >>
sc-users@...
> >>
http://lists.create.ucsb.edu/mailman/listinfo/sc-users> >>
> >
> >
> >
>
> _______________________________________________
> sc-users mailing list
>
sc-users@...
>
http://lists.create.ucsb.edu/mailman/listinfo/sc-users>
--
http://www.mcld.co.uk_______________________________________________
sc-users mailing list
sc-users@...
http://lists.create.ucsb.edu/mailman/listinfo/sc-users