\n",
"\n",
"

"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Today's project will require a lot of exploratory \"numerical\" math. In school, you are frequently presented a neatly packaged piece of math, without much discussion of where it comes from. In reality, before a useful mathematical object receives a nice pedagogical description in your text book, it takes a few decades (or centuries) for mathematicians to wrap their heads around it. During this time, an \"exploratory\" approach that simply \"plays\" with different properties of the object is very helpful and it results in quite a bit of unearthed beauty. We will try to explore the beauty of one particularly wondrous object today: a fractal, namely the \"Mandelbrot Set\"."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"However, given that the work will be both numerical and visual, we will go through an introductory \"scientific programming\" and \"scientific visualizations\" toolbox."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We will use this \"notebook\" interface for most of the work. This \"notebook\" interface is used by many scientist and engineers for numerical work (simulations, data analysis, etc) and documentation (like the text in this paragraph). The notebook is divided in \"cells\". By default the cells can be filled with computer code to be executed, or they can be changed to \"markdown\" cells, like this one, which are filled with text and description of the calculations."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note: To enter a cell for editing just select it and press \"enter\". To evaluate a cell (or render the text you wrote in it) press \"shift+enter\" while in the cell. To add a new cell, above or below a currently selected cell, press \"esc\" to exit the current cell and then press \"a\" or \"b\" to add a new cell."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# The numerical and plotting toolboxes\n",
"\n",
"Below we have a \"code\" cell, which can be used to evaluate programming code expressions. The last line of the cell is also printed back to you with its result.\n",
"\n",
"The programming language which we will use here is called \"Julia\" and it is particularly good at \"scientific\" programming that does a lot of numerical algebra.\n",
"\n",
"First, let us show how this can be used like a calculator."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1+2"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"π = 3.1415926535897..."
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pi"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can use it to evaluate functions as well (entities that take one or more numbers and spill out another number)."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5.65"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"abs(-5.65)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"8"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2^3"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can save expression results into variables for later use."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"7"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"whatever_name_I_want_for_my_variable = 5\n",
"whatever_name_I_want_for_my_variable + 2"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a_shorter_name = whatever_name_I_want_for_my_variable - 3\n",
"a_shorter_name"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And if we want to evaluate the same expression many times, we can create a \"function\", that does something to the variables and returns the result."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"my_very_important_expression (generic function with 1 method)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function my_very_important_expression(my_first_parameter, my_second_parameter)\n",
" my_intermediary_result = my_first_parameter - my_second_parameter\n",
" return 2*my_intermediary_result\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"12"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_very_important_expression(10,4)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Note to the instructor**

This is an “exploratory math” outreach activity, specifically aimed at dispelling the thrall of math phobia. There are two parts to that phobia - thinking that math is impossible to learn and that it is dull. Everybody agrees mathematics is useful, but less commonly appreciated, mathematics is something you can learn like anything else (nobody is “just bad at math”, but it seems a lot of people have wrongly internalized that rote memorization is all there is to math[1]). Moreover, something people miss when talking to kids is that mathematics is something that can be pretty. Here we use the prettiness to trick kids into playing with math. We avoid the “scary” algebra by using purely numerical work and a lot of guided exploration. To facilitate the exploration, we use a programming language as a calculating and plotting tool.

\n", "\n", "The final goal is to have the students be able to plot and explore natural fractals on their own. We will start by presenting a simple language for calculations and plotting (the Julia programming language). We learn the basics of manipulating lists of numbers, repeating operations until a condition is met, and plotting lines with given coordinates through the first hour or so. We introduce the notion of dynamical laws (using the example of population growth and avoiding any mathematical jargon) in the first half of the second hour. We introduce Mandelbrot’s “dynamical law” and then we let the students explore its convergence properties (by giving them the code to do that) for another half an hour. In the third hour we explain and rebuild that code from scratch.

\n", "\n", "

**From the very beginning be very clear with the students that this activity is exploring a very particular mathematical object that happens to be beautiful - we are not teaching general mathematical or computer science techniques and what we show them will _not_ be directly useful in class, _nor_ will it be particularly related to any mathematical techniques employed in computer generated art in general. We are exploring one pretty object in and endless see of mathematical beauty.**

Directions to how to approach the students is left in similar panels.

\n", "\n", "[1] See “A Mathematician's Lament” by Paul Lockhart, freely available on the Internet.

\n", "\n", "The activity is designed at Yale for SWE's Engineering Day.

\n", "\n",
"Have the students write a function that multiplies two numbers together and returns the result. Let them try on their own for a couple of minutes. If nobody volunteers to dictate a solution, let them work in pairs for a minute or two. Rely on the volunteers that are at the tables with the students to gauge whether they have succeeded at the task.\n",
"

\n",
"\n",
"In real code you probably will want shorter, easier to write names."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We will use a \"plotting\" library for our visualizations and we will introduce common ways to represent the information to be visualized on a computer."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"Talk about plotting numbers from a table on a sheet of paper or in Excel. Have your \"whiteboard monkey\" make a table of numbers (glasses sold at the lemonade stand over the course of the week) and have them plot them.\n",
"

"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"