## Projectile Motion with Python, Desmos, and Monte Carlo Simulation

I’ve written about my backwards approach to to projectile motion previously here, here, and here.

I had students solving the warm-up problem to that first lesson, which goes like this:

A student is at one end of a basketball court. He wants to throw a basketball into the hoop at the opposite end.

What information do you need to model this situation using the Geogebra model? Write down [______] = on your paper for any values you need to know to solve it using the model, and Mr. Weinberg will give you any information he has.
Find a possible model in Geogebra that works for solving this problem.
At what minimum speed he could throw the ball in order to get the ball into the hoop?

The students did what they usually do with the Geogebra projectile motion model and solved it with some interesting methods. One student lowered the hoop to the floor. Another started with a 45 degree angle, and then increased the speed successively until the ball made it into the hoop. Good stuff.

A student’s comment about making lots of guesses here got me thinking about finding solutions more algorithmically. I’ve been looking for new ways to play around with genetic algorithms and Monte Carlo methods since they are essentially guess and check procedures made productive by the power of the computer.

I wrote a Python program that does the following:

• Get information about the initial characteristics of the projectile and the desired final location.
• Make a large number of projectiles (guesses) with random values for angle and initial speed within a specified range.
• Calculate the ending position of all of the projectiles. Sort them by how far they end up compared to the desired target.
• Take the twenty projectiles with the least error, and use these values to define the initial values for a new, large number of projectiles.
• Repeat until the error doesn’t change much between runs.
• Report the projectile at the end with the least error.
• Report the entire procedure a number of times to see how consistent the ‘best’ answer is.

I’ve posted the code for this here at Github.

As a final step, I have this program outputting commands to graph the resulting projectile paths on Desmos. Pasting the result into the console while a Desmos calculator open, makes a nice graph for each of the generated projectiles and their intersecting at the desired target:

This is also on a live Desmos page here.

This shows that there is a range of possible answers, which is something I told my physics class based on their own solutions to the problem. Having a way to show (rather than tell) is always the better option.

I also like that I can change the nature of the answers I get if I adjust the way answers are sorted. This line in the code chooses how the projectile guesses are sorted by minimizing error:

` self.ordered = self.array.sort(key=lambda x: abs(x.error))`

If I change this to instead sort by the sum of error and the initial speed of the projectile, I get answers that are much closer to each other, and to the minimum speed necessary to hit the target:

Fun stuff all around.

## Computational Thinking and Algebraic Expressions

I am still reviewing algebra concepts in my Math 9 course with students. The whole unit is all about algebraic operations, but my students have seen this material at least once, in some cases two years running.

Not long ago, I made the assertion that the most harmful part of introducing students to the world of real-world algebra looks like this:

## Let x = the number of ________

Why is this so harmful?

For practiced mathematicians, math teachers, and students that have endured school math for long enough, there are a couple steps that actually happen internally before this step of defining variables. Establishing a context for the numbers and the operations that link them together are the most important part of producing a correct mathematical model for a given situation. A level of intuition and experience is necessary if one is going to successfully skip straight to this step, and most students don’t have this intuition or experience.

We have to start with the concrete because most people (including our students) start their thinking in concrete terms. This is the reason I have raved previously about the CME Project and the effectiveness of using their guess-check-generalize concept in introducing word problems to students. It forms an effective bridge between the numbers that students understand and the abstract concept of a variable. It encourages experimentation and analysis of whether a given answer matches the constraints of a problem.

This method, however, screams for computers to take care of the arithmetic so that students can focus on manipulating the variables involved. Almost all of the Common Core Standards for Mathematical Practice point toward this being an important focus for our work with students. I haven’t had a great point in my curriculum since I really started getting into computational thinking to try out my ideas from the beginning, but today gave me a chance to do just that.

Here’s how I introduced students to what I wanted them to do:

I then had them open up this spreadsheet and actually complete the missing elements of the spreadsheet on their own. Some students had learned to do similar tasks in a technology class, but some had not.
02 – SPR – Translating Algebraic Expressions

The students that needed to have conversations about tricky concepts like three less than a number had them with me and with other students when they came up. Students that didn’t quickly moved through the first set. I’d go and throw some different numbers for ‘a number’ and see that they were all changing as expected. Then we moved to a more abstract task:

It’s great to see that you know how to use different operations on the number in that cell. Now let’s generalize. Pick a variable you like – x, or N, or W – it doesn’t matter. What would each of these cells become then? Write those results together with the words in your notebook and show me when you’re done.

The ease with which students moved to this next task was much greater than it has ever been for me in past lessons. We also had some really great conversations about x*2 compared with 2x, and the fact that both are correct from an arithmetic standpoint, but one is more ‘traditional’ than the other.

Once students got to this point, I pushed them toward a slightly higher level task that still began concrete. This is the second sheet from the spreadsheet above:

Here we had multiple variables going at once, but this was not a stretch for most students. The key that I needed to emphasize here for some students was that the red text was all calculated. I wanted to put information in the black boxes with black text only, and have the spreadsheet calculate the red values. This required students to identify what the relationship between the variables needed to be to obtain the answer they knew in their head had to be true. This is CCSS MP2, almost verbatim.

This is all solidifying into a coherent framework of using spreadsheet and programming tools to reinforce algebra instruction from the start. There’s still plenty to figure out, but this is a start. I’ll share what I come up with along the way.

## Class-sourcing data generation through games

In my newly restructured first units for ninth and tenth grade math, we tackle sets, functions, and statistics. In the past, teaching these topics have always involved collecting some sort of data relevant to the class – shoe size, birthday, etc. Even though making students part of the data collection has always been part of my plan, it always seems slower and more forced than I want it to be. I think the big (and often incorrect) assumption is that because the data is coming from students, they will find it relevant and enjoyable to collect and analyze.

This summer, I remembered a blog post from Dan Meyer not too long ago describing a brilliantly simple game shared by Nico Rowinsky on Twitter. I had tried this manually with pencil and paper and students since hearing about it. It always required a lot of effort collecting and ordering papers with student guesses, but student enthusiasm for the game usually compelled me to run a couple of rounds before getting tired of it. It screamed for a technology solution.

I spent some time this summer learning some of the features of the Meteor Javascript web framework after a recommendation from Dave Major. It has the real-time update capabilities that make it possible to collect numbers from students and reveal a scoreboard to all users simultaneously. You can see my (imperfect) implementation hosted at http://lownumber.meteor.com, and the code at Github here. Dave was, as always, a patient mentor during the coding process, eagerly sharing his knowledge and code prototypes to help me along.

If you want to start your own game with friends, go to lownumber.meteor.com/config/ and select ‘Start a new game’, then ask people to play. Wherever they are in the world, they will all see the results show up almost instantly when you hit the ‘Show Results’ button on that page. I hosted this locally on my laptop during class so that I could build a database of responses for analysis later by students.

The game was, as expected, a huge hit. The big payoff was the fact that we could quickly play five or six games in my class of twenty-two grade nine students in a matter of minutes and built some perplexity through the question of how one can increase his or her chances of winning. What information would you need to know about the people playing? What tools do we have to look at this data? Here comes statistics, kids.

It also quickly led to a discussion with the class about the use of computers to manage larger sets of data. Only in a school classroom would one calculate measures of central tendency by hand for a set of data that looks like this:

This set also had students immediately recognizing that 5000 was an outlier. We had a fascinating discussion when some students said that out of the set {2,2,3,4,8}, 8 should be considered an outlier. It led us to demand a better definition for outlier than ‘I know it when I see it’. This will come soon enough.

The game was also a fun way to introduce sets with the tenth graders by looking at the characteristics of a single set of responses. Less directly related to the goal of the unit, but a compelling way to get students interacting with each other through numbers. Students that haven’t tended to speak out in the first days of class were on the receiving end of class-wide cheers when they won – an easy channel for low pressure positive attention.

As you might also expect, students quickly figured out how to game the game. Some gave themselves entertaining names. Others figured out that they could enter multiple times, so they did, though still putting in their name each time. Some entered decimals which the program rounded to integers. All of these can be handled by code, but I’m happy with how things worked out as is.

If you want instructions on running this locally for your classroom, let me know. It won’t be too hard to set up.

## Rethinking the headache of reassessments with Python

One of the challenges I’ve faced in doing reassessments since starting Standards Based Grading (SBG) is dealing with the mechanics of delivering those reassessments. Though others have come up with brilliant ways of making these happen, the design problem I see is this:

• The printer is a walk down the hall from my classroom, requires an ID swipe, and possibly the use of a paper cutter (in the case of multiple students being assessed).
• We are a 1:1 laptop school. Students also tend to have mobile devices on them most of the time.
• I want to deliver reassessments quickly so I can grade them and get them back to students immediately. Minutes later is good, same day is not great, and next day is pointless.
• The time required to generate a reassessment is non-zero, so there needs to be a way to scale for times when many students want to reassess at the same time. The end of the semester is quickly approaching, and I want things to run much more smoothly this semester in comparison to last.

I experimented last fall with having students run problem generators on their computers for this purpose, but there was still too much friction in the system. Students forgot how to run a Python script, got errors when they entered their answers incorrectly, and had scripts with varying levels of errors in them (and their problems) depending on when they downloaded their file. I’ve moved to a web form (thanks Kelly!) for requesting reassessments the day before, which helps me plan ahead a bit, but I still find it takes more time than I think it should to put these together.

With my recent foray into web applications through the Bottle Python framework, I’ve finally been able to piece together a way to make this happen. Here’s the basic outline for how I think I see this coming together – I’m putting it in writing to help make it happen.

• Phase 1 – Looking Good: Generate cleanly formatted web pages using a single page template for each quiz. Each page should be printable (if needed) and should allow for questions that either have images or are pure text. A function should connect a list of questions, standards, and answers to a dynamic URL. To ease grading, there should be a teacher mode that prints the answers on the page.
• Phase 2 – Database-Mania: Creation of multiple databases for both users and questions. This will enable each course to have its own database of questions to be used, sorted by standard or tag. A user can log in and the quiz page for a particular day will automatically appear – no emailing links or PDFs, or picking up prints from the copier will be necessary. Instead of connecting to a list of questions (as in phase 1) the program will instead request that list of question numbers from a database, and then generate the pages for students to use.
• Phase 3 – Randomization: This is the piece I figured out last fall, and it has a couple components. The first is my desire to want to pick the standard a student will be quizzed on, and then have the program choose a question (or questions) from a pool related to that particular standard. This makes reassessments all look different for different students. On top of this, I want some questions themselves to have randomized values so students can’t say ‘Oh, I know this one – the answer’s 3/5’. They won’t all be this way, and my experience doing this last fall helped me figure out which problems work best for this. With this, I would also have instant access to the answers with my special teacher mode.
• Phase 4 – Sharing: Not sure when/if this will happen, but I want a student to be able to take a screenshot of their work for a particular problem, upload it, and start a conversation about it with me or other students through a URL. This will also require a new database that links users, questions, and their work to each other. Capturing the conversation around the content is the key here – not a computerized checker that assigns a numerical score to the student by measuring % wrong, numbers of standards completed, etc.

The bottom line is that I want to get to the conversation part of reassessment more quickly. I preach to my students time and time again that making mistakes and getting effective feedback is how you learn almost anything most efficiently. I can have a computer grade student work, but as others have repeatedly pointed out, work that can be graded by a computer is at the lower level of the continuum of understanding. I want to get past the right/wrong response (which is often all students care about) and get to the conversation that can happen along the way toward learning something new.

Today I tried my prototype of Phase 1 with students in my Geometry class. The pages all looked like this:

Though this wasn’t my goal at the beginning of the year, I’ve found that my technological and programming obsessions this year have focused on minimizing the paperwork side of this job and maximizing opportunities for students to get feedback on their work. I used to have students go up to the board and write out their work. Now I snap pictures on my phone and beam them to the projector through an Apple TV. I used to ask questions of the entire class on paper as an exit ticker, collect them, grade them, and give them back the next class. I’m now finding ways to do this all electronically, almost instantly, and without requiring students to log in to a third party website or use an arbitrary piece of hardware.

The central philosophy of computational thinking is the effort to utilize the strengths of  computers to organize, iterate, and use patterns to solve problems.  The more I push myself to identify my own weaknesses and inefficiencies, the more I am seeing how technology can make up for those negatives and help me focus on what I do best.

## What do I have wrong here? Computational thinking obsession continues

Another installment of my Hong Kong presentation titled ‘Why Computational Thinking matters.’ This is where my head is these days in figuring out how computers relate to what we do in class. My view is that activities like the one I describe in the video is more active than the way we (and I include myself in this group) usually attack word problems as part of our sequence.

[wpvideo IkQx3la4]

Help me flesh this out. I think there’s a lot here.

## Cell phone tracking, Processing, and computational thinking

I gave a survey to my students recently. My lowest score on any of the questions was ‘What I learn in this class will help me in real life.’ I’ve given this question before, and am used to getting less than optimal responses. I even think I probably had a higher score on this question than I have received previously, but it still bothers me that we are having this discussion. Despite my efforts to include more problem solving, modeling, and focusing on conceptual understanding related tasks over boring algorithmic lessons, the fact that I am still getting lower scores on this question compared to others convinces me that I have a long way to go.

I came up with this activity in response. It combines some of the ideas I learned in my Udacity course on robotic cars with the fact that nearly all my students carry cell phones. While I know many cell phones have GPS, it is my understanding that phones have used cell towers for a while to help with the process of locating phones. It always amazes me, for example, how my cell service immediately switches to roaming immediately when driving across the US-Canada border, even when I had a non-GPS capable phone.

My students know how to find distance using the distance formula and sets of coordinates, but they were intrigued by the idea of going backwards – if you know your distance from known locations, can you figure out your own location? The idea of figuring this out isn’t complicated. It can most easily be done by identifying intersections of circles as shown below:

One of my students recalled this method of solving the problem from what he saw in the movie Taken 2 , and was quickly able to solve the problem this way graphically in Geogebra. Most students didn’t follow this method though – the general trend was to take a guess and adjust the guess to reduce the overall error until the distances were as close to the given distances as possible.

I got them to also look at other situations – if only two measurements to known locations are known, where could the cell phone be located? They played around to find that there were two locations in this case. I again pointed out that they were following an algorithm that could easily be taught to a computer.

I then showed them a Processing sketch that went through this process. It is not a true particle filter that goes through resampling to improve the guessed location over time, but it does use the idea of making a number of guesses and highlighting the ones with the lowest error. The idea of making 300,000 random guesses and choosing the ones that are closest to the set of distances is something that computers are clearly better at than humans are. There are analytical ways of solving this problem, but this is a good way of using the computational power of the computer to make a brute force calculation to get an approximate answer to the question.

You can look at the activity we did in class here:
Using Cell Phones to Track Location