Question: Best way to fill a matrix using a math function and conditional statements

Bear with me, while I've used Maple V, I've never done any actual programming in Maple as I've almost entirely used Matlab.  Right now I've got an issue with trying to fill a square matrix using a sinc function [(sin(Pi*x)/(Pi*x)].  Here's my procedure:


 

Note that the arguments for sin and for the denominator are written as they are so as to define the domain of  the sinc function as [-m/2,m/2] along a row and [-n/2,n/2] along a column of the matrix I want to fill and so that I the arguments can have decimal values.  Also note the conditional statements there because when the sine argument and the denominator yields Pi*0, the function equals 1 despite the zero in the denominator.

So I'm unsure how to fill a matrix of some size m x n using the procedure (or a function if that makes the programming easier).  Here's how I would write the code for Matlab:

Z=zeros(2001,2001);
X=(-5:.005:5)';
Y=(-5:.005:5)';

count1=1;

for j=-5:.005:5
    count2=1;
    for k=-5:.005:5
        Z(count1,count2)=sinc(k)^2*sinc(j)^2;
        count2=count2+1;
    end
    count1=count1+1;
end

Given my meager experience writing Maple code, I'm a bit flumoxed.

Thanks, and don't feel like you have to be gentle. No one ever accused me of writing elegant code.

Thanks

Please Wait...