From: Joseph on
There seems to be a mistake in this code. I don't think
for fun = funvector

does what you want.





"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.
From: dpb on
David Romero-Antequera wrote:
....

> 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?
....

Profile, profile, profile...

For all we know from the supplied data the bulk of the time is spent in
the user-supplied functions.

Don't waste time trying to optimize until know where the ouch actually is.

--