# MATLAB: Matrix whose elements depend on its indicies

I am trying to put the function

$$f(\mu,\nu) = i^{\nu-\mu} \sum_{0}^{19} H_{\mu-\nu}(7j) + \delta_{\mu,\nu}\ ,$$

$\mu, \nu =-3,-2,...2,3$ into a 7x7 matrix, where $H$ is the Hankel function of the first kind, and the $\delta$ represents the Kronecker Delta.

How can this be done, on MATLAB?

A simple approach:

F = eye(7); % gives you the Kronecker delta part
for mu = -3:3
for nu = -3:3
isum = 0; % temporary variable for the sum
for j = 0:19
isum = isum + besselh(mu-nu,7.0*j);
end
F(4+mu,4+nu) = F(4+mu,4+nu) + (1i)^(nu-mu) * isum;
end
end


For systems larger than 7x7, it might be wise to precompute the bessel function sums for each possible value of $\mu-\nu$ and look up the desired value.