-
- Notifications
You must be signed in to change notification settings - Fork 359
adding draft of monte carlo chapter #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
chapters/monte_carlo/monte_carlo.md Outdated
{% method %} | ||
{% sample lang="jl" %} | ||
[import:2-8, lang:"julia"](code/julia/monte_carlo.jl) | ||
{% sample lang="cpp" %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have you got C++ here?
chapters/monte_carlo/monte_carlo.md Outdated
{% sample lang="jl" %} | ||
### Julia | ||
[import, lang:"julia"](code/julia/monte_carlo.jl) | ||
{% sample lang="cpp" %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here?
Both of those should have been removed. Thanks! |
chapters/monte_carlo/monte_carlo.md Outdated
| ||
Well, imagine you have a square. | ||
The area of the square is simple, $$\text{Area}_{\text{square}} = \text{length} \times \text{width}$$. | ||
Since it's a square, the $$\text{length}$$ and $$\text{width}$$ are the same, so the formula is technically just $$\text{Area}_{\text{square}} = \text{legth}^2$$. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
length not legth.
Ok, typo fixed! Thanks for the catch! |
How do you compile and visualize someone else's PR? |
chapters/monte_carlo/monte_carlo.md Outdated
It doesn't take too many lines to get something simple going. | ||
Here, we are just integrating a circle, like we described above; however, there is a small twist and trick. | ||
Instead of calculating the area of the circle, we are instead trying to find the value of $$\pi$$, and | ||
rather than integrating the entire circle, we are only integrating the upper left quadrant of the circle from $$-1 < x,y < 1$$. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean upper right quadrant and do you mean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo. Should have written
Will fix when I get home.
@jiegillet go to the fork and the branch then clone it (on unix use this command |
end | ||
| ||
pi_estimate = 4*pi_count/(n*radius^2) | ||
println("Percent error is: ", signif(100*(pi - pi_estimate), 3), " %") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you need to divide (pi - pi_estimate) by pi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, you are right. Fixing soon. Thanks!
This one took me a while to make the images. I had to find some old code and update it.
I couldn't decide between using a gif or three images side-by-side for showing that with more points, you get a better result. This version has 3 images.
What do you guys think? For now, the book is online-only, so I think a gif is ultimately fine. There are a lot of other things we will need to change if we ever want to actually print this book... so maybe it's alright to have good visualizations?