Teaching simple programming and Monte Carlo methods with Geogebra CAS
Hi!
I want to incorporate more programming to my math lessons & I wanna do this with Geogebra.
So lets say that I want to simulate this simple problem:
Roll two D20 dice. What is the probability that the geometric mean of these two dice rolls is a integer?
If possible, I want to do the following commands in CAS-view.
Geogebras Algebra has this variable: numberofsuccess:= 0
And now in to CAS-view
LINE 1. // a:=RandomBetween(1 ,20)
LINE 2. // b:=RandomBetween(1 ,20)
LINE 3. // sqrt(a*b) - floor( sqrt(a*b) )
LINE 4. // if( $3==0, numberofsuccess:=numberofsuccess +1 )
LINE 5. // command that repeats LINES 1-4 2500 times ??
LINE 6. // after this I can just do the division: numberofsuccess/2500 ... ... ...
OK the ROW 4 does not work because Geogebra "does not understand" c:=c+1 ... so first of all how do I do ROW 4? Can I utilise lists or spreadsheet in doing this?
Thanks already for your help.
You make a list
MC:=Sequence(Zip(sqrt(A*B)−floor(sqrt(A*B)),A,{Random(1,20)},B,{Random(1,20)}),i,1,n)
CountIf(x ≟ 0,MC)
Or you want to write it to 1 line...
Do you want to test IsInteger() or mod(a,floor(a))=0
You should avoid to test difference =0
You make a list
MC:=Sequence(Zip(sqrt(A*B)−floor(sqrt(A*B)),A,{Random(1,20)},B,{Random(1,20)}),i,1,n)
CountIf(x ≟ 0,MC)
Or you want to write it to 1 line...
Do you want to test IsInteger() or mod(a,floor(a))=0
You should avoid to test difference =0
Thank you! Works like a charm.
Can you elaborate a little bit why modulo is better than difference?
As Michael told IsInteger() is not working in CAS you can use it in AlgebraView.
I dont know wether the calculation of difference with floor is exact (for sure not in AlgebraView) what will mean the difference not equals exact 0 (e.g. better to test abs(difference)<10^-15 ). Mod is a CAS function that hopefully works exact.
all your commands work in algebra view. why we must to use CAS
If you make long lists CAS is slow. Use Algerra View with long sequences.
M
Comments have been locked on this page!