Markov Chains. Simon added a slider.

Simon also worked on a Markov Chains projects this weekend, trying to introduce a slider into his text generating code.

“A Markov Chain can be described as a sequence of random “states” where each new state is conditional only on the previous state. (…) An n-gram is a contiguous sequence of N elements. (…) Using an N-gram model, we can use a markov chain to generate text where each new word or character is dependent on the previous word (or character) or sequence of words (or characters)”, Daniel Shiffman writes.

In other words, Markov Chains can be used to generate text automatically based on a source text. For some reason, Simon’s slider only worked in the minimum stand (“least sense”, generating words from 2-letter combinations). When turned to maximum, it only returned the same one and a half words all the time. Simon gave up at that point:


The rest of the code comes from Daniel Shiffman’s Markov Chains Coding Challenge. This coding challenge is part of the Programming A to Z course, one of the courses that Daniel Shiffman has taught at the Interactive Telecommunications Program at NYU’s Tisch School of the Arts.

This is the chapter on Markov Chains:

Oscillation and Drag Force: Spring Project.

Today Simon was watching Daniel Shiffman’s tutorials to learn about drag force and how to apply it when building a spring simulation in p5.js. Simon wrote the formula for drag force in Microfost Word and looked up all the variables:

Drag Force 23 Apr 2017 2

While building a spring in p5.js, Simon talks about the 3 laws of Isaac Newton:

The project is based upon Daniel Shiffman’s book The Nature of Code, specifically Chapter 3 (Oscillation). Simon spent the rest of the evening studying “simple harmonic motion”, periods and amplitudes. Here is an excerpt from Daniel Shiffman’s book:

y = sine(x)
You’ll notice that the output of the sine function is a smooth curve alternating between –1 and 1. This type of a behavior is known as oscillation, a periodic movement between two points. Plucking a guitar string, swinging a pendulum, bouncing on a pogo stick—these are all examples of oscillating motion.
This is what is known as simple harmonic motion (or, to be fancier, “the periodic sinusoidal oscillation of an object”). It’s going to be a simple program to write, but before we get into the code, let’s familiarize ourselves with some of the terminology of oscillation (and waves).
Simple harmonic motion can be expressed as any location (in our case, the x location) as a function of time, with the following two elements:
  • Amplitude: The distance from the center of motion to either extreme
  • Period: The amount of time it takes for one complete cycle of motion
Looking at the graph of sine, we can see that the amplitude is 1 and the period is TWO_PI; the output of sine never rises above 1 or below -1; and every TWO_PI radians (or 360 degrees) the wave pattern repeats.

Inequalities Machine 2.0

Simon has nearly completed the basic equations and inequalities course on Khan Academy.

Algebra Progress 6 Mar 2017

Every time his math teacher comes they solve a couple of inequalities from the course and what happens next is that Simon goes over to his desktop to check his answers in the “Inequalities machine” he programmed! He often has to change the program to fit a new inequality format, so it takes some time. Luckily the math teacher understands how awesome this is. I also think it’s the first time Simon has really programmed something for practical use!

This is how Simon solves the inequalities, by typing them:

Inequalities 3 Mar 2017

Testing the answer in the “Inequalities Machine”:


The original “Inequalities Machine” Simon programmed back in February:

Inequality Machine 20 feb 2017