Added monte carlo simulation example
dc / build (push) Successful in 15s Details

This commit is contained in:
Marco Cetica 2024-03-15 08:42:15 +01:00
parent d0156fae3a
commit b247dadbba
Signed by: marco
GPG Key ID: 45060A949E90D0FD
2 changed files with 29 additions and 1 deletions

View File

@ -259,6 +259,20 @@ lB -1 * lD + lA # POSITIVE DELTA
0 lL x
```
17. Estimate $\pi$ using Monte Carlo simulation
```
10 k
[ 0 1 @ sX 0 1 @ sY ] sR
[ lX 2 ^ sX lY 2 ^ sY ] sQ
[ 0 ;A 1 + 0 :A ] sI
[ 1 lX lY + <=I ] sC
[ lR x lQ x lC x 1 + d lN >=L ] sL
0 0 :A
0 6500 sN
lL x 0 ;A lN /
4 * p
```
## License
[GPLv3](https://choosealicense.com/licenses/gpl-3.0/)

16
man.md
View File

@ -3,7 +3,7 @@ title: dc
section: 1
header: General Commands Manual
footer: Marco Cetica
date: March 14, 2024
date: March 15, 2024
---
@ -503,6 +503,20 @@ c 1 lL x # Clear the stack, add lower bound, load and execute macro
0 lL x
```
13. Estimate *pi* using Monte Carlo simulation
```
10 k
[ 0 1 @ sX 0 1 @ sY ] sR
[ lX 2 ^ sX lY 2 ^ sY ] sQ
[ 0 ;A 1 + 0 :A ] sI
[ 1 lX lY + <=I ] sC
[ lR x lQ x lC x 1 + d lN >=L ] sL
0 0 :A
0 6500 sN
lL x 0 ;A lN /
4 * p
```
# AUTHORS
The original version of the **dc** command was written by Robert Morris and Lorinda Cherry.
This version of **dc** is developed by Marco Cetica.