Question:

Maple Syntax -- difficulty with basic concepts?

by  |  earlier

0 LIKES UnLike

I am having difficulty with 'Maple' syntax. Please see below and explain each line's purpose (the overall purpose of the procedure is to determine how many people must be at a gathering place before the probability is greater than or equal to1/2 that at least 2 people share the same birthday):

> birthday:=proc(N,M)

local L,day,j,i,d,count ;

count:=0;

day:=rand(1..366);

for j from 1 to M do

L:=[];

for i from 1 to N do

d:=day();

if member(d,L)=true then count:=count+1; break fi;

L:=[op(L),d];

od;

od;

evalf(count/M);

end:

You could also e-mail me directly to sandorgr8@yahoo.com so that I can obtain a better understanding with a dialog.

Thanks in advance!

 Tags:

   Report

1 ANSWERS


  1. birthday:=proc(N,M)    --> define function birthday(N=# of people, M=# of trials)

    local L,day,j,i,d,count ;  --> define variables used in the function

    count:=0;  --> initialize counter for the number of duplicate birthdays

    day:=rand(1..366);  --> define a function that is a random number representing the birthday

    for j from 1 to M do  --> loop over the number of trials

    L:=[];  -->  initialize the birthday list

    for i from 1 to N do  --> loop over the number of people

    d:=day();  --> generate a random birthday

    if member(d,L)=true then count:=count+1; break fi;  --> if this is a duplicate birthday, mark it so, and quit checking

    L:=[op(L),d];  --> Otherwise, add this birthday to the list

    od;  --> end of inner loop

    od;  --> end of outer loop

    evalf(count/M);  --> get a decimal approximation of the fraction of trials in which there was a duplicate birthday

    end:  --> end of the function

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.