Skip to content

Commit

Permalink
Merge pull request #760 from nature-of-code/notion-update-docs
Browse files Browse the repository at this point in the history
[Notion] Update docs
  • Loading branch information
shiffman committed Feb 12, 2024
2 parents 0bdce81 + 1442eed commit 5a3482b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion content/00_randomness.html
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ <h3 id="calculating-mean-and-standard-deviation">Calculating Mean and Standard D
<p>The standard deviation is the square root of the variance: 15.13.</p>
</div>
<p>In the case of height values from 200 to 300, you probably have an intuitive sense of the mean (average) as 250. However, what if I were to say that the standard deviation is 3? Or 15? What does this mean for the numbers? The graphs depicted in Figure 0.2 should give you a hint. On the left is a distribution with a very low standard deviation, with the majority of the values piling up around the mean (they don’t deviate much from the standard). The version on the right has a higher standard deviation, so the values are more evenly spread out from the average (they deviate more).</p>
<p>The numbers work out as follows: given a population, 68 percent of its members will have values in the range of one standard deviation from the mean, 95 percent within two standard deviations, and 99.7 percent within three standard deviations. Given a standard deviation of 5 pixels, only 0.3 percent of the monkey heights will be less than 235 pixels (three standard deviations below the mean of 250) or greater than 265 pixels (three standard deviations above the mean of 250). Meanwhile, 68 percent of the monkey heights will be from 245 to 255 pixels.</p>
<figure>
<div class="col-list">
<div>
Expand All @@ -351,7 +352,6 @@ <h3 id="calculating-mean-and-standard-deviation">Calculating Mean and Standard D
</div>
<figcaption>Figure 0.2: Two example bell curves of a normal distribution, with a low (left) and high (right) standard deviation</figcaption>
</figure>
<p>The numbers work out as follows: given a population, 68 percent of its members will have values in the range of one standard deviation from the mean, 95 percent within two standard deviations, and 99.7 percent within three standard deviations. Given a standard deviation of 5 pixels, only 0.3 percent of the monkey heights will be less than 235 pixels (three standard deviations below the mean of 250) or greater than 265 pixels (three standard deviations above the mean of 250). Meanwhile, 68 percent of the monkey heights will be from 245 to 255 pixels.</p>
<p>Luckily, to use a normal distribution of random numbers in a p5.js sketch, you don’t have to do any of these calculations manually. Instead, the <code>randomGaussian()</code> function takes care of the math and returns random numbers with a normal distribution:</p>
<pre class="codesplit" data-code-language="javascript">function draw() {
// Ask for a Gaussian random number.
Expand Down
10 changes: 6 additions & 4 deletions content/03_oscillation.html
Original file line number Diff line number Diff line change
Expand Up @@ -710,11 +710,13 @@ <h3 id="exercise-312">Exercise 3.12</h3>
</figure>
</div>
<h2 id="spring-forces">Spring Forces</h2>
<div class="half-width-right">
<figure>
<img src="images/03_oscillation/03_oscillation_11.png" alt="Figure 3.14: A spring with an anchor and bob">
<figcaption>Figure 3.14: A spring with an anchor and bob</figcaption>
</figure>
</div>
<p>Exploring the mathematics of triangles and waves has been lovely, but perhaps you’re starting to miss Newton’s laws of motion and vectors. After all, the core of this book is about simulating the physics of moving bodies. In <a href="#properties-of-oscillation">“Properties of Oscillation”</a>, I modeled simple harmonic motion by mapping a sine wave to a range of pixels on a canvas. <a href="#exercise-37">Exercise 3.7</a> asked you to use this technique to create a simulation of a bob hanging from a spring with the <code>sin()</code> function. That kind of quick-and-dirty, one-line-of-code solution won’t do, however, if what you really want is a bob hanging from a spring that responds to other forces in the environment (wind, gravity, and so on). To achieve a simulation like that, you need to model the force of the spring by using vectors.</p>
<figure>
<img src="images/03_oscillation/03_oscillation_11.png" alt="Figure 3.14: A spring with an anchor and bob">
<figcaption>Figure 3.14: A spring with an anchor and bob</figcaption>
</figure>
<p>I’ll consider a spring to be a connection between a movable<em> </em>bob (or weight) and a fixed anchor point (see Figure 3.14).</p>
<p>The force of the spring is a vector calculated according to Hooke’s law, named for Robert Hooke, a British physicist who developed the formula in 1660. Hooke originally stated the law in Latin: “<em>Ut tensio, sic vis</em>,” or “As the extension, so the force.” Think of it this way:</p>
<p><span class="highlight">The force of the spring is directly proportional to the extension of the spring.</span></p>
Expand Down
3 changes: 1 addition & 2 deletions content/08_fractals.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ <h3 id="implementing-recursive-functions">Implementing Recursive Functions</h3>
someFunction();
}</pre>
</div>
<p>Not only is this allowed, but it’s quite encouraged! In fact, it’s essential to the way I’ll implement the Cantor set. Functions that call themselves are known as <strong>recursive functions</strong>, and they’re well suited for solving certain problems. For example, some mathematical calculations are implemented recursively; the most well-known example is the <strong>factorial</strong>.</p>
<p>The factorial of any number <em>n</em>, usually written as <em>n</em>!, is defined as follows:</p>
<p>Not only is this allowed, but it’s quite encouraged! In fact, it’s essential to the way I’ll implement the Cantor set. Functions that call themselves are known as <strong>recursive functions</strong>, and they’re well suited for solving certain problems. For example, some mathematical calculations are implemented recursively; the most well-known example is the <strong>factorial</strong>. The factorial of any number <em>n</em>, usually written as <em>n</em>!, is defined as follows:</p>
<div data-type="equation">n! = n × (n - 1) × … × 3 × 2 × 1</div>
<div data-type="equation">0! = 1</div>
<p>Here’s a nonrecursive function in JavaScript that uses a <code>for</code> loop to calculate the factorial of a number:</p>
Expand Down
Binary file modified content/images/03_oscillation/03_oscillation_11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5a3482b

Please sign in to comment.