Skip to content

Conversation

leios
Copy link
Member

@leios leios commented May 20, 2018

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?

@leios leios added Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) Chapter This provides a new chapter. (md files are edited) labels May 20, 2018
{% method %}
{% sample lang="jl" %}
[import:2-8, lang:"julia"](code/julia/monte_carlo.jl)
{% sample lang="cpp" %}
Copy link
Contributor

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?

{% sample lang="jl" %}
### Julia
[import, lang:"julia"](code/julia/monte_carlo.jl)
{% sample lang="cpp" %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here?

@leios
Copy link
Member Author

leios commented May 20, 2018

Both of those should have been removed. Thanks!


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$$.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

length not legth.

@leios
Copy link
Member Author

leios commented May 21, 2018

Ok, typo fixed! Thanks for the catch!

@jiegillet
Copy link
Member

How do you compile and visualize someone else's PR?

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$$.
Copy link
Member

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 $$0 &lt; x,y &lt; 1$$?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo. Should have written $$0 &lt; x,y &lt; 1$$

Will fix when I get home.

@Gathros
Copy link
Contributor

Gathros commented May 22, 2018

@jiegillet go to the fork and the branch then clone it (on unix use this command git clone -b <branch> <url>) then gitbook install and then gitbook serve, then you can see the book at localhost:4000.

end

pi_estimate = 4*pi_count/(n*radius^2)
println("Percent error is: ", signif(100*(pi - pi_estimate), 3), " %")
Copy link
Member

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

Copy link
Member Author

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!

@leios leios merged commit fd6020e into algorithm-archivists:master May 28, 2018
@leios leios deleted the monte_carlo_chapter branch July 17, 2018 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Chapter This provides a new chapter. (md files are edited) Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.)

3 participants