On 2/4/2013 8:12 AM, Michal Kvasnicka wrote:
> Hello, I need to vectorize (to speedup code) the following loop:
>
> [dim, n]=size(x);
> A=zeros(n,n);
> for i=1:n
> for j=1:i
> r=norm(x(:,i)x(:,j));
> temp=feval(phi,r, const);
> A(i,j)=temp;
> A(j,i)=temp;
> end
> end
>
> where function "phi" is defined as
> function u=phi(r, const)
> u=exp(0.5*r.*r/(const*const));
>
> Any hints?
Most trivial first  get rid of feval() and put the function evaluation
inline since it's so trivial. That'll help quite a bit I'd expect.
Second, since the diagonal is exp(0), no need to compute it; so run the
loop to i1
May help some to only set the lower (or upper) block and then transpose
afterwards instead of in loop to augment...
I didn't think too much about the actual norm() part; I've got a meeting
to head to now but I'd think griddata() may help...

