Jump to content



Photo
- - - - -

Monte Carlo Π Estimation [Fx-5800P]

fx-5800P

  • Please log in to reply
8 replies to this topic

#1 Tritonio

Tritonio

    Casio Addict

  • Members
  • PipPipPip
  • 77 posts
  • Gender:Male

  • Calculators:
    fx-5800P, fx-991ES+, fx-991EX, HP Prime, fx-9750GIII, fx-3650P II

Posted 12 November 2014 - 01:56 AM

Here's a little program that tries to estimate π using a Monte Carlo method.

Be patient. :-) After an hour it should have reached 3.14.

0→I
0→O
Lbl 1
If Ran# ²+Ran# ²<1:Then
1+I→I
Else
1+O→O
IfEnd
Locate 1,1,(I÷(I+O))×4
Goto 1

Edited by Tritonio, 12 November 2014 - 02:00 AM.


#2 somebody1234

somebody1234

    Casio Addict

  • Members
  • PipPipPip
  • 51 posts

  • Calculators:
    Casio fxcg10
    Casio fx-9860GII
    Casio Classpad 400

Posted 12 November 2014 - 08:02 AM

Why did you make this?

(Just curious, it looks really inefficient)



#3 Tritonio

Tritonio

    Casio Addict

  • Members
  • PipPipPip
  • 77 posts
  • Gender:Male

  • Calculators:
    fx-5800P, fx-991ES+, fx-991EX, HP Prime, fx-9750GIII, fx-3650P II

Posted 12 November 2014 - 12:07 PM

For fun. It is one of the least efficient methods but it's soooo simple.



#4 Krtyski

Krtyski

    Casio Freak

  • Members
  • PipPipPipPip
  • 132 posts
  • Gender:Male
  • Location:Tokyo, Japan
  • Interests:programming, smooth Jazz and 4-wheel driving.

  • Calculators:
    FX-502P, FX-602P, FX-603P,
    fx-4000P, fx-7000G,
    fx-4500P, fx-4800P
    fx-5800P,
    CFX-9850G,
    CFX-9850GC PLUS
    fx-9860G,
    fx-9860G AU,
    fx-9860G Slim
    fx-9860GII SD,
    fx-9860GII-2,
    fx-9860GII-2 SD,
    fx-CG20, fx-CG50,
    fx-CP400
    fx-9860GIII
    fx-9750GIII
    fx-7400GIII

Posted 15 November 2014 - 05:09 PM

If you use Isz I instead of I+1->I, also use => instead of If / Else / IfEnd, then time to get result would be a bit shorter. please note do not start from I=0, O=0, but from I=1, O=1.

 

1→I:1O
Lbl 1
IRan# ²+Ran# ²<1=>Isz I:Isz O
Locate 1,1,(I÷(I+O))×4
Goto 1


Edited by Krtyski, 15 November 2014 - 05:13 PM.


#5 Tritonio

Tritonio

    Casio Addict

  • Members
  • PipPipPip
  • 77 posts
  • Gender:Male

  • Calculators:
    fx-5800P, fx-991ES+, fx-991EX, HP Prime, fx-9750GIII, fx-3650P II

Posted 15 November 2014 - 05:30 PM

If you use Isz I instead of I+1->I, also use => instead of If / Else / IfEnd, then time to get result would be a bit shorter. please note do not start from I=0, O=0, but from I=1, O=1.

 

1→I:1O
Lbl 1
IRan# ²+Ran# ²<1=>Isz I:Isz O
Locate 1,1,(I÷(I+O))×4
Goto 1

 

Indeed you can shorten it more. Although you made a mistake. You left lsz O running on every iteration this way so the locate line should be like this:

Locate 1,1,(I÷O4

 

Also why should I start from 1?



#6 Krtyski

Krtyski

    Casio Freak

  • Members
  • PipPipPipPip
  • 132 posts
  • Gender:Male
  • Location:Tokyo, Japan
  • Interests:programming, smooth Jazz and 4-wheel driving.

  • Calculators:
    FX-502P, FX-602P, FX-603P,
    fx-4000P, fx-7000G,
    fx-4500P, fx-4800P
    fx-5800P,
    CFX-9850G,
    CFX-9850GC PLUS
    fx-9860G,
    fx-9860G AU,
    fx-9860G Slim
    fx-9860GII SD,
    fx-9860GII-2,
    fx-9860GII-2 SD,
    fx-CG20, fx-CG50,
    fx-CP400
    fx-9860GIII
    fx-9750GIII
    fx-7400GIII

Posted 15 November 2014 - 07:22 PM

Oh, you are right.

 

In scripting 

A=>B:C

C is always processed. This is indeed wrong.

 

With 'Isz O' when O comes to zero (0), a command next to Isz O is skipped. Isz O is not equivalent to O+1->O. That's why O should not start with zero, but it should start with 1, 0.1, 0.001 so on...


Edited by Krtyski, 15 November 2014 - 07:23 PM.


#7 Krtyski

Krtyski

    Casio Freak

  • Members
  • PipPipPipPip
  • 132 posts
  • Gender:Male
  • Location:Tokyo, Japan
  • Interests:programming, smooth Jazz and 4-wheel driving.

  • Calculators:
    FX-502P, FX-602P, FX-603P,
    fx-4000P, fx-7000G,
    fx-4500P, fx-4800P
    fx-5800P,
    CFX-9850G,
    CFX-9850GC PLUS
    fx-9860G,
    fx-9860G AU,
    fx-9860G Slim
    fx-9860GII SD,
    fx-9860GII-2,
    fx-9860GII-2 SD,
    fx-CG20, fx-CG50,
    fx-CP400
    fx-9860GIII
    fx-9750GIII
    fx-7400GIII

Posted 15 November 2014 - 08:11 PM

I played around with following a but modified program;
 
1->I:1->O:1->D
Lbl 1
If Ran#2+Ran#2<1
Then Isz I
Else Isz O
IfEnd
Isz D
Locate 1,1,D
Locate 1,2,(I÷(O+O))x4

Getkey=0=>Goto 1

 

By hitting any key the calculation stops. I tried several times. When D is about 1500, the result was about between 3.13 to 3.15,

As the theory says accuracy is like this. It's interesting.

 



#8 Tritonio

Tritonio

    Casio Addict

  • Members
  • PipPipPip
  • 77 posts
  • Gender:Male

  • Calculators:
    fx-5800P, fx-991ES+, fx-991EX, HP Prime, fx-9750GIII, fx-3650P II

Posted 16 November 2014 - 12:28 AM

Oh, you are right.

 

In scripting 

A=>B:C

C is always processed. This is indeed wrong.

 

With 'Isz O' when O comes to zero (0), a command next to Isz O is skipped. Isz O is not equivalent to O+1->O. That's why O should not start with zero, but it should start with 1, 0.1, 0.001 so on...

 

I think it first increases the variable and then checks if it's zero. So it should work... I mean it works for me at least...



#9 Krtyski

Krtyski

    Casio Freak

  • Members
  • PipPipPipPip
  • 132 posts
  • Gender:Male
  • Location:Tokyo, Japan
  • Interests:programming, smooth Jazz and 4-wheel driving.

  • Calculators:
    FX-502P, FX-602P, FX-603P,
    fx-4000P, fx-7000G,
    fx-4500P, fx-4800P
    fx-5800P,
    CFX-9850G,
    CFX-9850GC PLUS
    fx-9860G,
    fx-9860G AU,
    fx-9860G Slim
    fx-9860GII SD,
    fx-9860GII-2,
    fx-9860GII-2 SD,
    fx-CG20, fx-CG50,
    fx-CP400
    fx-9860GIII
    fx-9750GIII
    fx-7400GIII

Posted 16 November 2014 - 01:08 PM

At last I enjoyed with following souce;

 

0->I:0->O:1->D

Lbl 1

Ran#2+Ran#2<1=>IszI

Isz O:Isz D

Locate 1,1,D

Locate 1,2,(I÷O)x4

 

Yes, the first time of Isz I gives I=1, so the jump never happen, as you said.

Please note the last Locate display (I÷O)X4, so this works correctly.







Also tagged with one or more of these keywords: fx-5800P

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users