Game Theory

UCLA professor Peter Nonacs teaches behavioral theory by letting students “cheat” in his “insanely hard” exams by letting them use whatever resources they want, including the web and working together. His objective is to have his students learn game theory by actually practicing it:

Much of evolution and natural selection can be summarized in three short words: “Life is games.” In any game, the object is to win—be that defined as leaving the most genes in the next generation, getting the best grade on a midterm, or successfully inculcating critical thinking into your students. An entire field of study, Game Theory, is devoted to mathematically describing the games that nature plays. Games can determine why ant colonies do what they do, how viruses evolve to exploit hosts, or how human societies organize and function.

— Nonacs (2013): Why I Let My Students Cheat On Their Game Theory Exam on PopSci.com.

My Environmental Science students are facing a similar problem with their final project. It’s a group project — their objective is to revamp the recycling system at school to make it work better — and I’ve been trying to get out of their way as much as possible. Not only do they have to figure out how to solve an environmental problem (they have an outline of how to do so in their text, but they have to figure out how to put it into practice), but they also have to figure out how to work together as a group to get the project done and write up a final report. The latter problem tends to be the harder, but in having to figure out how to lead, follow, and work as a team, it’s probably the more important lesson in the long term.

Worm Eating Warbler

A Worm Eating Warbler.

A Worm Eating Warbler flew into the glass window where the middle school students were taking their annual standardized test. It did not survive.

My students tell me that the same thing happened last year. Now I’m wondering just how often it happens, and if I should start a daily survey.

Curiously, despite their name, these birds rarely eat worms, they prefer insects and spiders.

(Thanks to Scott Woodbury for help with the identification.)

The School’s Campus

The diverse ecosystems on the TFS campus — from the creek to the grassy school grounds to the reforesting slope to the forested ridge — are well shown in this sketch. Diagram by C.J. (used with permission).

I think that one of the reasons I really like this diagram is because it places the school as a small piece in a much larger ecological context. A student in my Environmental Science class drew it for an assignment. We’d hiked all the way from the creek to the ridge in the company of Scott Woodbury from the Shaw Nature Center, and I asked them to draw a diagram showing the different ecological regions. I’d expected top down maps, which is what almost all the other students did. When I asked why the perspective view, she said just didn’t know how to draw trees from the top down.

Conflict over water

One of the articles my students brought to our Environmental Science discussion was about the growing fears about wars over water. Even within the U.S.A. there are significant conflicts, as demonstrated by this NPR article.

Texas has tried to buy Oklahoma water from the state, its cities and towns, and its Native American tribes. But Oklahoma lawmakers have blocked those efforts with a string of laws restricting out-of-state water exports.

The view in Texas is that Oklahoma isn’t even using its full allocation of Red River water. Oklahomans respond that Texas hasn’t gotten serious enough about conservation.

“Our poor, poor thirsty people in Dallas, Texas,” muses state Sen. Jerry Ellis, a Democrat who represents southeastern Oklahoma. “There’s nobody thirsty in Dallas, Texas.”

— Wertz,J., 2013: Thirsty States Take Water Battle To Supreme Court on NPR.

The full article:

P.S. Lauren Markham has an article about environmental “refugees” forced to leave Ethiopia because of the changing rainfall patterns over the last eight years.

Programming Numerical Integration with Python (and Javascript)

Numerically integrating the area under the curve using four trapezoids.

I gave a quick introduction to programming for my calculus class, which has been working on numerical integration.

Numerical integration is usually used for functions that can’t be integrated (or not easily integrated) but for this example we’ll use a simple parabolic function so we can compare the numerical results to the analytical solution (as seen here).

With the equation:

 f(x) = -\frac{1}{4} x^2 + x + 4

To find the area under the curve between x = 1 and x = 5 we’d find the definite integral:

 Area = \int_{_1}^{^5} \left(-\frac{x^2}{4}  + x + 4 \right) \,dx

which gives the result:

 Area = 17 \frac{2}{3}  = 17.6\bar{6}

For numerical integration, we break the area of concern into a number of trapezoids, find the areas of all the trapezoids and add them up.

We’ll define the left and right boundaries of the area as a and b, and we can write the integral as:

 Area = \int_{_a}^{^b} f(x) \,dx

The left and right boundaries of the area we’re interested in are defined as a and b respectively. The area of each trapezoid is defined as An.

We also have to choose a number of trapezoids (n) or the width of each trapezoid (dx). Here we choose four trapezoids (n = 4), which gives a trapezoid width of one (dx = 1).

The area of the first trapezoid can be calculated from its width (dx) and the height of the two upper ends of the trapezoid (f(x0) and f(x1).

So if we define the x values of the left and right sides of the first trapezoids as x0 and x1, the area of the first trapezoid is:

 A_1 = \frac{f(x_{_0})+f(x_{_1})}{2} dx

For this program, we’ll set the trapezoid width (dx) and then calculate the number of trapezoids (n) based on the width and the locations of the end boundaries a and b. So:

 n = \frac{b-a}{dx}

and the sum of all the areas will be:

 \displaystyle\sum\limits_{i=1}^{n} \frac{f(x_{i-1})+f(x_{i})}{2} dx

We can also figure out that since the x values change by the same value (dx) for every trapezoid, it’s an arithmetic progression, so:

 x_{i-1} = a + (i-1) dx

and,

 x_{i} = a + i \cdot dx

so our summation becomes:

 \displaystyle\sum\limits_{i=1}^{n} \frac{f(a+(i-1)dx)+f(a + i \cdot dx)}{2} dx

Which we can program with:

numerical_integration.py

# the function to be integrated
def func(x):
    return -0.25*x**2 + x + 4

# define variables
a = 1.          # left boundary of area
b = 5.          # right boundary of area
dx = 1          # width of the trapezoids

# calculate the number of trapezoids
n = int((b - a) / dx)

# define the variable for area
Area = 0

# loop to calculate the area of each trapezoid and sum.
for i in range(1, n+1):
    #the x locations of the left and right side of each trapezpoid
    x0 = a+(i-1)*dx
    x1 = a+i*dx

    #the area of each trapezoid
    Ai = dx * (func(x0) + func(x1))/ 2.

    # cumulatively sum the areas
    Area = Area + Ai

#print out the result.
print "Area = ", Area

And the output looks like

>>> 
Area =  17.5
>>> 

While the programming is pretty straightforward, it was a bit of a pain getting Python to work for one of my students who is running Windows 8. I still have not figured out a way to get it to work properly, so I’m considering trying to do it using Javascript.

Update

The javascript functions for numerical integration:

function numerically_integrate(a, b, dx, f) {
	
	// calculate the number of trapezoids
	n = (b - a) / dx;
	
	// define the variable for area
	Area = 0;
	
	//loop to calculate the area of each trapezoid and sum.
	for (i = 1; i <= n; i++) {
		//the x locations of the left and right side of each trapezpoid
		x0 = a + (i-1)*dx;
		x1 = a + i*dx;
		
		// the area of each trapezoid
		Ai = dx * (f(x0) + f(x1))/ 2.;
		
		// cumulatively sum the areas
		Area = Area + Ai	
		
	} 
	return Area;
}

//define function to be integrated
function f(x){
	return -0.25*Math.pow(x,2) + x + 4;
}

// define variables
a = 1;		// left boundary of area
b = 5;		// right boundary of area
dx = 1;		// width of the trapezoids
	
// print out output
alert("Area = "+ numerically_integrate(a, b, dx, f));

This is a demonstration of a full html file that uses the function, and should work in any modern browser (download files: numerical-integration.zip).

Update 2

I’ve added the above javascript code to the embeddable graphs to allow it to calculate and display numerical integrals: you can change the values in the interactive graph below.

Drawing Daffodils

It’s spring, and what better time to study meiosis and dissect daffodils.

Students collect daffodils for dissection.

Daffodilusa (pdf) has nice description of how to dissect daffodils. However, I had students collect the flowers, and sketch the outsides and insides (longitudinal bisection) before I gave them the handout.

I wanted them to practice drawing diagrams and observing features first, before we got into the discussion of what the parts were and what they did, to make sure they’d not forgotten all they’d learned when we did our animal dissections last semester.

They laid out their grids, did some very nice drawings, and then labeled what they’d drawn, based on the handout, over the weekend.