From: David Romero-Antequera on
"us " <us(a)neurol.unizh.ch> wrote in message <i3c8g1$i2m$1(a)fred.mathworks.com>...
> "David Romero-Antequera" <dromero_fisica(a)yahoo.es> wrote in message <i3c7i1$adm$1(a)fred.mathworks.com>...
> > Hello, everyone.
> >
> > I need some suggestion to make the following function faster.
> >
> > function psi=NLF(z,y,funvector,orig_size)
> > psi=zeros(size(y));
> > Y=ifft2(reshape(y,orig_size));
> > for fun=funvector
> > fY=feval(fun{2},z,Y);
> > kY=fun{1}.*fft2(fY);
> > kY=kY(:);
> > psi=psi+kY;
> > end
> > end
> >
> > where z is a double scalar, y is a complex matrix, funvector is a cell array with double scalars in the first column and function handles in the second, and orig_size is a 2x1 matrix.
> >
> > As you can see, I need to compute the inverse Fourier transform of the vector Y, then evaluate it into several user-provided functions and compute the Fourier transform and add all of that together. This is part of an ODE, so you might expect that this is going to be evaluated THOUSANDS of times, and every second counts.
> >
> > Any suggestions?
> > Thanks in advance.
>
> just minor thoughts...
>
> % from
> psi=zeros(size(y));
> % to
> psi=zeros(size(y),'double');
> % from
> fY=feval(fun{2},z,Y);
> % to
> fY=fun{2}(z,Y);
>
> us

Suppresing feval does not do that much for the computing, but it is far more elegant. Thanks!
From: Walter Roberson on
David Romero-Antequera wrote:

> That's something that it is not in my hands. On the other hand, the user
> provided function, can be something that can't be optimized anymore, like
>
> @(t,f) abs(f).^2;
>
> I just want to make sure that there's nothing else that I can do.

Would f be real or complex? If it would be real, then

@(t,f) f.^2

would be more efficient.


Profile first, _then_ worry.