PsiSquared

Robin Seibel

40 Reputation

2 Badges

9 years, 115 days

MaplePrimes Activity


These are questions asked by PsiSquared

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

I'm new to Maple, and I come from using Matlab.  Apparently my Matlab way of thinking isn't working on Maple.  I'm trying  to ride a bit of code that simulates flipping a coin 1000 times.  The code counts one partiuclar result (1=heads) at the end prints that result.

 

Here's the code:

 

dice:=proc()

count:=0:  

for i from 1 to 10000 do  

roll := rand(1..2):  

roll:=()  

if (roll=1) then count:=count+1 end if  

end do  

print(count)  

 I get errors saying I didn't terminate my loops correctly.  Help, please.

1 2 Page 2 of 2