|
Peter Boettcher <boettcher@ll.mit.edu> wrote in message
<muyod8sgouc.fsf@G99-Boettcher.llan.ll.mit.edu>...
>
> Please include quotes for context.
>
> Dave first wrote:
>
> > > > Hi, I have a calculation which i'm trying to speed
up with
> > > > no great success. It is quite a bottleneck for an
> > > > optimisation run.
> > > >
> > > > Basically I have lots of 2x2 matrices which all
need
> > > > multiplying and this is the bottleneck in my code.
This is
> > > > currently achieved by:
> > > >
> > > > for g=1:length(r0i)
> > > > prodH=prodH*[ai(g),bi(g);ci(g),di(g)];
> > > > end
> > > >
> > > > Any improvement in this would significantly speed
up the
> > > > calculation; is there a better way of doing this?
Feel free
> > > > to ask me questions if i've not been clear. Thanks
for your
> > > > help.
>
> To which I responded:
>
> > > See the mex file NDFUN at
http://www.mit.edu/~pwb/matlab/
> > >
> > > The 'mprod' subfunction will do this, if you assemble
your ai/bi/ci/di
> > > into a 3D matrix, one 2x2 matrix per "page".
>
>
> "Dave Brackett" <davebrackett@hotmail.com> writes:
>
> > sorry i'm still not getting it! :S
> >
> > do you think you could show how i can change my code
using
> > the method you suggest please?
> > thanks for your patience, and sorry for the double post!
>
> Assume ai/bi/ci/di are all column vectors:
>
> M = reshape([ai bi ci di].', 2, 2, []);
>
> % Now M(:,:,1) is the first 2x2 matrix, M(:,:,2) is the
second, etc.
>
> prodH = ndfun('mprod', M);
>
>
> -Peter
ah ok, i get it now thanks for bearing with me! Cheers.
|