Question: Asking about error in maple code (integration related to monte carlo method)

Dear,

I wrote a code used for calculate integration using monte carlo method (in order to get random results).

I also wrote the code using maplet in order to get the interface.

However, when I finished I could not receive the result because of the error:

Error, (in Maplets:-Elements:-Maplet) `Maplets:-Elements:-ElementTable[typ]` does not evaluate to a module

I do not understand this error and how to correct it.

I need the help from others.

Here is my code:

tinh:=module()
export tinh1;global tinh2,tinh3;
tinh2:=proc()
global r1,r2,r01,r02,d0,d,a,b,c,i,x,y,z,MM,hits,n,rf,actual,estimate,erro,percenterror,mm,cm;
mm:=1;cm:=10^(-1);
if Maplets:-Tools:-Get('DDB1')="mm" then a:=mm
fi:
if Maplets:-Tools:-Get('DDB1')="cm" then a:=cm
fi:
if Maplets:-Tools:-Get('DDB2')="mm" then b:=mm
fi:
if Maplets:-Tools:-Get('DDB2')="cm" then b:=cm
fi:
if Maplets:-Tools:-Get('DDB3')="mm" then c:=mm
fi:
if Maplets:-Tools:-Get('DDB3')="cm" then c:=cm
fi:
r01:=Maplets:-Tools:-Get('TF1'::algebraic);
r02:=Maplets:-Tools:-Get('TF2'::algebraic);
d0:=Maplets:-Tools:-Get('TF3'::algebraic);
r1:=r01*a;r2:=r02*b;d:=d0*c;
n:=Maplets:-Tools:-Get('TF4'::algebraic);
hits:=0;
MM:=100000*n;
rf:=rand(0..MM);
for i to n do
x:=evalf(3.14*rf()/MM);
y:=evalf(0.16*rf()/MM);
if(y<=(r1*r2*(sin(x))^2/((r1^2+r2^2+d^2-2*r1*r2*cos(x))^(1/2)*(d+(r1^2+r2^2+d^2-2*r1*r2*cos(x))^(1/2))))) then hits:=hits+1;
fi;
od;
actual:=evalf(int((r1*r2*(sin(z))^2/((r1^2+r2^2+d^2-2*r1*r2*cos(z))^(1/2)*(d+(r1^2+r2^2+d^2-2*r1*r2*cos(z))^(1/2)))),z=0..3.14));
estimate:=evalf(3.14*0.16*hits/n);
erro:=evalf(estimate-actual);
percenterror:=evalf(erro*100/actual);
return(actual):
end proc: use Maplets,Maplets:-Elements in
tinh1:=Maplet(Window("Geometry factor",[[Label("Source radius",'halign'=left,'font'=Font("Time",bold,14),'foreground'='blue'),TextField['TF1'](),DropDownBox['DDB1'](["mm","cm"])],[label("detector radius",'halign'=left,'font'=Font("Time",bold,14),'foreground'='blue'),TextField['TF2'](),DropDownBox['DDB2'](["mm","cm"])],[Label("Distance",'halign'=left,'font'=Font("Time",bold,14),'foreground'='blue'),TextField['TF3'](),DropDownBox['DDB3'](["mm","cm"])],[Label("The number of repetition",'halign'=left,'font'=Font("Time",bold,14),'foreground'='blue'),TextField['TF4']()],[Label("Geometry factor",'halign'=left,'font'=Font("Time",bold,14),'foreground'='red'),TextBox['TB1']()],[Button(("Evaluate",'halign'=center,'font'=Font("Time",bold,14),'foreground'='red'),Evaluate('TB1'='tinh2'))],[Button("CLEAR",'onclick'=Action(SetOption('TF1'=""),SetOption('TF2'=""),SetOption('TF3'=""),SetOption('TF4'=""),SetOption('TB1'=""))),Button("EXIT",Shutdown())]])):
Maplets[Display](tinh1):
end use:
end module:

Please help me to correct it.

Thanks so much!



Please Wait...