# Category Archives: Problem Solving

As part of preparing for our impending move from Indy to Grand Rapids, my family and I have made a couple of visits to the area. These by necessity combine business with pleasure, since our three kids (ages 2, 5, and 7) don’t handle extended amounts of business well. On the last visit, we spent some time at the Grand Rapids Childrens Museum, the second floor of which is full of stuff that could occupy children — and mathematicians — for hours. This “exhibit” was, for me, one of the most evocative. Have a look:

I asked this on Twitter a few days ago, but I’ll repost it here: In the spirit of Dan Meyer’s Any Questions? meme, what questions come to mind as you watch this? Particularly math, physics, etc. questions.

One other thing — just after I wrapped up the video on this, someone put one of the little discs rolling on the turntable and it did about a dozen graceful, perfect three-point hypocycloids before falling off the table.

Filed under Geometry, Math, Problem Solving

## A problem with “problems”

I have a bone to pick with problems like the following, which is taken from a major university-level calculus textbook. Read it, and see if you can figure out what I mean.

This is located in the latter one-fourth of a review set for the chapter on integration. Its position in the set suggests it is less routine, less rote than one of the early problems. But what’s wrong with this problem is that it’s not a problem at all. It’s an exercise. The difference between the two is enormous. To risk oversimplifying, in an exercise, the person doing the exercise knows exactly what to do at the very beginning to obtain the information being requested. In a problem, the person doesn’t. What makes an exercise an exercise is its familiarity and congruity with prior exercises. What makes a problem a problem is the lack of these things.

The above is not a problem, it is an exercise. Use the Midpoint Rule with six subintervals from 0 to 24. That’s the only part of the statement that you even have to read! The rest of it has absolutely nothing with bees, the rate of their population growth, or the net amount of population growth. A student might be turning this in to an instructor who takes off points for incorrect or missing units, and then you have to think about bees and time. Otherwise, this exercise is pure pseudocontext.

Worst of all, this exercise might correctly assess students’ abilities to execute a numerical integration algorithm, but it doesn’t come close to measuring whether a student understands what an integral is in the first place and why we are even bringing them up. Even if the student realizes an integral should be used, there’s no discussion of how to choose which method and which parameters within the method, or why. Instead, the exercise flatly tells students not only to use an integral, but what method to use and even how many subdivisions. A student can get a 100% correct answer and have no earthly idea what integration has to do with the question.

A simple fix to the problem statement will change this into a problem. Keep the graph the same and change the text to:

The graph below shows the rate at which a population of honeybees was growing, in bees per week. By about how many bees did the population grow after 24 weeks?

This still may not be a full-blown problem yet — and it’s still pretty pseudocontextual, and the student can guess there should be an integral happening because it’s in the review section for the chapter on integration —  but at least now we have to think a lot harder about what to do, and the questions we have to answer are better. How do I get a total change when I’m given a rate? Why can’t I just find the height of the graph at 24? And once we realize that we have to use an integral — and being able to make that realization is one of the main learning objectives of this chapter, or at least it should be — there are more questions. Can I do this with an antiderivative? Can I use geometry in some way? Should I use the Midpoint Rule or some other method? Can I get by with, say, six rectangles? or four? or even two? Why not use 24, or 2400? Is it OK just the guesstimate the area by counting boxes?

I think we who teach calculus and those who write calculus books must do a better job of giving problems to students and not just increasingly complicated exercises. It’s very easy to do so; we just have to give less information and fewer artificial cues to students, and force students to think hard and critically about their tools and how to select the right combination of tools for the job. No doubt, this makes grading harder, but students aren’t going to learn calculus in any real or lasting sense if they don’t grapple with these kinds of problems.

Filed under Calculus, Critical thinking, Math, Problem Solving, Teaching

## What correlates with problem solving skill?

About a year ago, I started partitioning up my Calculus tests into three sections: Concepts, Mechanics, and Problem Solving. The point values for each are 25, 25, and 50 respectively. The Concepts items are intended to be ones where no calculations are to be performed; instead students answer questions, interpret meanings of results, and draw conclusions based only on graphs, tables, or verbal descriptions. The Mechanics items are just straight-up calculations with no context, like “take the derivative of $y = \sqrt{x^2 + 1}$“. The Problem-Solving items are a mix of conceptual and mechanical tasks and can be either instances of things the students have seen before (e.g. optimzation or related rates problems) or some novel situation that is related to, but not identical to, the things they’ve done on homework and so on.

I did this to stress to students that the main goal of taking a calculus class is to learn how to solve problems effectively, and that conceptual mastery and mechanical mastery, while different from and to some extent independent of each other, both flow into mastery of problem-solving like tributaries to a river. It also helps me identify specific areas of improvement; if the class’ Mechanics average is high but the Concepts average is low, it tells me we need to work more on Concepts.

I just gave my third (of four) tests to my two sections of Calculus, and for the first time I started paying attention to the relationships between the scores on each section, and it felt like there were some interesting relationships happening between the sections of the test. So I decided to do not only my usual boxplot analysis of the individual parts but to make three scatter plots, pairing off Mechanics vs. Concepts, Problem Solving vs. Concepts, and Mechanics vs. Problem Solving, and look for trends.

Here’s the plot for Mechanics vs. Concepts:

That r-value of 0.6155 is statistically significant at the 0.01 level. Likewise, here’s Problem Solving vs. Concepts:

The r-value here of 0.5570 is obviously less than the first one, but it’s still statistically significant at the 0.01 level.

But check out the Problem Solving vs. Mechanics plot:

There’s a slight upward trend, but it looks disarrayed; and in fact the r = 0.3911 is significant only at the 0.05 level.

What all this suggests is that there is a stronger relationship between conceptual knowledge and mechanics, and between conceptual knowledge and problem solving skill, than there is between mechanical mastery and problem solving skill. In other words, while there appears to be some positive relationship between the ability simply to calculate and the ability to solve problems that involve calculation (are we clear on the difference between those two things?), the relationship between the ability to answer calculus questions involving no calculation and the ability to solve problems that do involve calculation is stronger — and so is the relationship between no-calculation problems and the ability to calculate, which seems really counterintuitive.

If this relationship holds in general — and I think that it does, and I’m not the only one — then clearly the environment most likely to teach calculus students how to be effective problem solvers is not the classroom primarily focused on computation. A healthy, interacting mixture of conceptual and mechanical work — with a primary emphasis on conceptual understanding — would seem to be what we need instead. The fact that this kind of environment stands in stark contrast to the typical calculus experience (both in the way we run our classes and the pedagogy implied in the books we choose) is something well worth considering.

## This week in screencasting: Optimization-palooza

My calculus class hit optimization problems this week — or it might be better to say the class got hit by optimization problems. These are tough problems because of all their many moving parts, especially the fact that one of those parts is to build the model you plan to optimize. Most of my students have had calculus in high school, but too many calculus courses in high school as well as college focus almost primarily on algorithms for computation and spend little to no time with how to create a model in the first place. Classes that are so structured are doing massive harm to students in a number of ways, but that’s for another post or two.

Careful study of worked-out examples is an essential part of understanding optimization problems (though not the only part, and this alone isn’t sufficient). The textbook has a few of these. The professor can provide more, but class time really isn’t best spent just by having the professor put examples on the board. Class time should also be spent working on optimization problems with the professor there to provide guidance. And since I can’t spend 8-10 class days both working examples and giving students time to work themselves, screencasts on optimization problems have been the obvious solution.

This week I did screencasts for four problems. Here they are (one problem needed two screencasts):

To my students’ great credit, they have embraced YouTube as a great source of help in calculus. They’ve utilized not only these screencasts but many other ones, most of them excellently produced, and now doing a search on YouTube is an essential component of studying for many of them. I think that’s a great approach, obviously.

## Why change how we teach?

Sometimes when I read or hear discussions of innovation or change in teaching mathematics or other STEM disciplines, whether it’s me or somebody else doing the discussing, inevitably there’s the following response:

What do we need all that change for? After all, calculus [or whatever] hasn’t changed that much in 400 years, has it?

I’m not a historian of mathematics, so I can’t say how much calculus has or hasn’t changed since the times of Newton and Leibniz or even Euler. But I can say that the context in which calculus is situated has changed — utterly. And it’s those changes that surround calculus that are forcing the teaching of calculus (any many other STEM subjects) to change –radically.

What are those changes?

First, the practical problems that need to be solved and the methods used to solve them have changed. Not too long ago, practical problems could be neatly compartmentalized and solved using a very small palette of methods. I know some things about those problems from my Dad, who was an electrical engineer for 40 years and was with NASA during the Gemini and Apollo projects. The kinds of problems he’d get were: Design a circuit board for use in the navigational system of the space capsule. While this was a difficult problem that needed trained specialists, it was unambiguous and could be solved with more or less a subset of the average undergraduate electrical engineering curriculum content, plus human ingenuity. And for the most part, the math was done by hand and on slide rules (with a smattering of newfangled mechanical calculators) and the design was done with stuff from a lab — in other words, standard methods and tools for engineers.

So it is with calculus or almost any STEM discipline these days. Students today will not go on to work with simple, cleanly-defined, well-posed problems that fit neatly into a box. Nor will they be always doing things by hand; they will be using technology to solve problems, and this requires both a different way of representing the models (for calculus, think “functions”) they use and the flexibility to anticipate the problems that the methods themselves create. This is not what Newton or Leibniz had in mind, but it is the way things are. Our teaching must therefore change to give students a fighting chance at solving these problems, by emphasizing multiple representations of functions, multiple methods for solution of problems, and attention to the problems created by the methods. And of course, we also must focus on teaching problem-solving itself and on the ability to acquire new skills and information independently, because if so much has changed between 1965 and 1995, we can expect about the same amount of change in progressively shorter time spans in the future.

Also, the people who solve these problems, and what we know about how those people learn, have changed. It seems undeniable that college students are different than they were even 20 years ago, much less 200 years ago. Although they may not be natively fluent in the use of technology, they are certainly steeped in technology, and technology is a primary means for how they interact with the rest of the world. Students in college today bring a different set of values, a different cultural context, and a different outlook to their lives and how they learn. This executive summary of research done by the Pew Research Foundation goes into detail on the characteristics of the Millenial generation, and the full report (PDF, 1.3 Mb) — in addition to our own experiences — highlights the differences in this generation versus previous ones. These folks are not the same people we taught in 1995; we therefore cannot expect to teach them in the same way and expect equal or better results.

We also know a lot more now about how people in general, and Millenials in particular, learn things than we did just a few years ago. We are gradually, but also rapidly, realizing through rigorous education research that there are other methods of teaching out there besides lecture and that these methods work better than lecture does in many situations. Instructors are honing the research findings into usable tools through innovative classroom practices that yield statistically verifiable improvements over more traditional ways of teaching. Even traditional modes of teaching are finding willing and helpful partners in various technological tools that lend themselves well to classroom use and student learning. And that technology is improving in cost, accessibility, and performance at an exponential pace, to the point where it just doesn’t make sense not to use it or think about ways teaching can be improved through its use.

Finally, and perhaps at the root of the first two, the culture in which these problems, methods, people, and even the mathematics itself is situated has changed. Technology drives much of this culture. Millenials are highly connected to each other and the world around them and have little patience — for better or worse — for the usual linear, abstracted, and (let’s face it) slow ways in which calculus and other STEM subjects are usually presented. The countercultural force that tends to discourage kids from getting into STEM disciplines early on is probably stronger today than it has ever been, and it seems foolish to try to fight that force with the way STEM disciplines have been presented to students in the past.

Millenials are interested to a (perhaps) surprising degree in making the world a better place, which means they are a lot more interested in solving problems and helping people than they are with epsilon-delta definitions and deriving integrals from summation rules. The globalized economy and highly-connected world in which we all live has made almost every problem worth solving multidisciplinary. There is a much higher premium now placed on getting a list of viable solutions to a problem within a brief time span, as opposed to a single, perfectly right answer within an unlimited time span (or in the time span of a timed exam).

Even mathematics itself has a different sort of culture now than it did even just ten years ago. We are seeing the emergence of massively collaborative mathematical research via social media, the rise of computational proofs from controversy to standard practice, and computational science taking a central role among the important scientific questions of our time. Calculus may not have changed much but its role in the larger mathematical enterprise has evolved, just in the last 10-15 years.

In short, everything that lends itself to the creation of meaning in the world today — that is, today’s culture — has changed from what it used to be. Even the things that remain essentially unchanged from their previous states, like calculus, must fit into a context that has changed.

All this change presents challenges and opportunities for STEM educators. It’s challenging to go back to calculus, and other STEM disciplines, and think about things like: What are the essential elements of this subject that really need to be taught, as opposed to just the topics we really like? What new facets or topics need to be factored in? What’s the best way to factor those in, so that students are really prepared to function in the world past college? And, maybe most importantly, How do we know our students are really prepared? There’s a temptation to burrow back in to what worked for us, when faced with such daunting challenges, but that really doesn’t help students much — nor does it tap into the possibilities of making our subjects, and our students, richer.

## Student (mis)understanding of the equals sign

Interesting report here (via Reidar Mosvold) about American students’ misunderstanding of the “equals” sign and how that understanding might feed into a host of mathematical issues from elementary school all the way to calculus. According to researchers Robert M. Capraro and Mary Capraro at Texas A&M,

About 70 percent of middle grades students in the United States exhibit misconceptions, but nearly none of the international students in Korea and China have a misunderstanding about the equal sign, and Turkish students exhibited far less incidence of the misconception than the U.S. students.

Robert Capraro, in the video at the link above, makes an interesting point about the “=” sign being used as an operator. He makes a passing reference to calculators, and I wonder if calculators are partly to blame here. After all, if you want to calculate 3+5 on a typical modern calculator, what do you do? You hit “3”, then “+”, then “5”… and then hit the “=” button. The “=” key is performing an action — it’s an operator! In fact, I suspect that if you gave students that sequence of calculator keystrokes and asked them which one performs the mathematical operation, most would say “=” rather than the true operator, “+”. The technology they use, handheld calculators, seems to be training them to think in exactly the wrong way about “=”. What we have labelled as the “=” key on a calculator is really better labelled as “Enter” or “Execute”.

In fact, the old-school HP calculators, like this HP 33c, didn’t have “=” buttons at all:

That’s because these calculators used Reverse Polish Notation, in which the 3 + 5 calculation would have been entered “3”, then “5”, “+”, then “Enter” — and then you’d get an answer. What HP calculators label as “Enter”, on a typical modern calculator would be labelled “=”, and in that syntax lies a lot of the problem, it seems.

The biggest problem I seem to encounter with “=” sign use is that students use it to mark a transition between steps in a problem. For example, when solving the equation $3x - 2 = 10$ for x, you might see:

$3x - 2 = 10 = 12 = x = 4$

The thought process can be teased out of this atrocious syntax, but clearly this is not acceptable math — even though the last bit of that line (x=4) is a correct statement. If the student would just put spaces, tabs, or even a semicolon between the steps, it would be a big improvement. But many students are so trained to believe that the right answer — the ending “4” — is all that matters, they have little experience with crafting a good solution, or even realizing that a mathematical solution is supposed to be a form of communication at all.

What are some of the student misconceptions you’ve seen (or perpetrated!) with the “=” sign? If you’re a teacher, how have you approached mending those misconceptions?

## Calculus and conceptual frameworks

I was having a conversation recently with a colleague who might be teaching a section of our intro programming course this fall. In sharing my experiences about teaching programming from the MATLAB course, I mentioned that the thing that is really hard about teaching programming is that students often lack a conceptual framework for what they’re learning. That is, they lack a mental structure into which they can place the topics and concepts they’re learning and then see those ideas in their proper place and relationship to each other. Expert learners — like some students who are taking an intro programming course but have been coding since they were 6 years old — have this framework, and the course is a breeze. Others, possibly a large majority of students in a class, have never done any kind of programming, and they will be incapable of really learning programming until they build a conceptual framework to  handle it. And it’s the prof’s job to help them build it.

Afterwards, I thought, this is why teaching intro programming is harder than teaching calculus. Because students who make it all the way into a college calculus surely have a well-developed conceptual framework for mathematics and can understand where the topics and methods in calculus should fit. Right? Hello?

It then hit me just how wrong I was. Students coming into calculus, even if they’ve had the course before in high school, are not guaranteed to have anything like an appropriate conceptual framework for calculus. Some students may have no conceptual framework at all for calculus — they’ll be like intro programming students who have never coded — and so when they see calculus concepts, they’ll revert back to their conceptual frameworks built in prior math courses, which might be robust and might not be. But even then, students may have multiple, mutually contradictory frameworks for mathematics generally owing to different pedagogies, curricula, or experiences with math in the past.

Take, for example, the typical first contact that calculus students get with actual calculus in the Stewart textbook: The tangent problem. The very first example of section 2.1 is a prototype of this problem, and it reads: Find an equation of the tangent line to the parabola $y = x^2$ at the point $P(1,1)$. What follows is the usual initial solution: (1) pick a point $Q$ near $(1,1)$, (2) calculate the slope of the secant line, (3) move $Q$ closer to $P$ and recalculate, and then (4) repeat until the differences between successive approximations dips below some tolerance level.

What is a student going to do with this example? The ideal case — what we think of as a proper conceptual handling of the ideas in the example — would be that the student focuses on the nature of the problem (I am trying to find the slope of a tangent line to a graph at a point), the data involved in the problem (I am given the formula for the function and the point where the tangent line goes), and most importantly the motivation for the problem and why we need something new (I’ve never had to calculate the slope of a line given only one point on it). As the student reads the problem, framed properly in this way, s/he learns: I can find the slope of a tangent line using successive approximations of secant lines, if the difference in approximations dips below a certain tolerance level. The student is then ready for example 2 of this section, which is an application to finding the rate at which a charge on a capacitor is discharged. Importantly, there is no formula for the function in example 2, just a graph.

But the problem is that most students adopt a conceptual framework that worked for them in their earlier courses, which can be summarized as: Math is about getting right answers to the odd-numbered exercises in the book. Students using this framework will approach the tangent problem by first homing in on the first available mathematical notation in the example to get cues for what equation to set up. That notation in this case is:

$m_{PQ} = \frac{x^2 - 1}{x-1}$

Then, in the line below, a specific value of x (1.5) is plugged in. Great! they might think, I’ve got a formula and I just plug a number into it, and I get the right answer: 2.5. But then, reading down a bit further, there are insinuations that the right answer is not 2.5. Stewart says, “…the closer $x$ is to 1…it appears from the tables, the closer $m_{PQ}$ is to 2. This suggests that the slope of the tangent line $t$ should be $m = 2$.” The student with this framework must then be pretty dismayed. What’s this about “it appears” the answer is 2? Is it 2, or isn’t it? What happened to my 2.5? What’s going on? And then they get to example 2, which has no formula in it at all, and at that point any sane person with this framework would give up.

It’s also worth noting that the Stewart book — and many other standard calculus books — do not introduce this tangent line idea until after a lengthy precalculus review chapter, and that chapter typically looks just like what students saw in their Precalculus courses. These treatments do not attempt to be a ramp-up into calculus, and presages of the concepts of calculus are not present. If prior courses didn’t train students on good conceptual frameworks, then this review material actually makes matters worse when it comes time to really learn calculus. They will know how to plug numbers and expressions into a function, but when the disruptively different math of calculus appears, there’s nowhere to put it, except in the plug-and-chug bin that all prior math has gone into.

So it’s extremely important that students going into calculus get a proper conceptual framework for what to do with the material once they see it. Whose responsibility is that? Everybody’s, starting with…

• the instructor. The instructor of a calculus class has to be very deliberate and forthright in bending all elements of the course towards the construction of a framework that will support the massive amount of material that will come in a calculus class. This includes telling students that they need a conceptual framework that works, and informing them that perhaps their previous frameworks were not designed to manage the load that’s coming. The instructor also must be relentless in helping students put new material in its proper place and relationship to prior material.
• But here the textbooks can help, too, by suggesting the framework to be used; it’s certainly better than not specifying the framework at all but just serving up topic after topic as non sequiturs.
• Finally, students have to work at constructing a framework as well; and they should be held accountable not only for their mastery of micro-level calculus topics like the Chain Rule but also their ability to put two or more concepts in relation to each other and to use prior knowledge on novel tasks.

What are your experiences with helping students (in calculus or otherwise) build useable conceptual frameworks for what they are learning? Any tools (like mindmapping software), assessment methods, or other teaching techniques you’d care to share?

## Boxplots: Curiouser and curiouser

The calculus class took their third (and last) hour-long assessment yesterday. In the spirit of data analytics ala the previous post here, I made boxplots for the different sections of the test (Conceptual Knowledge (CK), Computation (C), and Problem Solving (PS)) as well as the overall scores. Here are the boxplots for this assessment — put side-by-side with the boxplots for the same sections on the previous assessments. “A2” and “A3” mean Assessments 2 and 3.

Obviously there is still a great deal of improvement to be had here — the fact that the class average is still below passing remains unacceptable to me — but there have been some definite gains, particularly in the conceptual knowledge department.

What changed between Assessment 2 and Assessment 3? At least three things:

• The content changed. Assessment 2 was over derivative rules and applications; Assessment 3 covered integration.
• The way I treated the content in class changed. Based on the results of Assessment 2, I realized I needed to make conceptual work a much greater part of the class meetings. Previously the class meetings had been about half lecture, with time set aside to work “problems” — meaning, exercises, such as “find the critical numbers of $y = xe^{-x}$. Those are not really problems that assess conceptual knowledge. So I began to fold in more group work problems that ask students to reason from something other than a calculation. I stressed these problems from the textbook more in class. I tried to include more such problems in WeBWorK assignments — though there are precious few of them to be had.
• The level of lip service I gave to conceptual problems went up hugely. Every day I was reminding the students of the low scores on Conceptual Knowledge on the test and that the simplest way to boost their grades in the class would be to improve their conceptual knowledge. I did not let their attention leave this issue.

Somewhere in a combination of these three things we have the real reason those scores went up. I tend to think the first point had little to do with it. Integration doesn’t seem inherently any easier to understand conceptually than differentiation, particularly at this stage in the course when differentiation is relatively familiar and integration is brand new. So I think that simply doing more conceptual problems in class and stressing the importance of conceptual knowledge in class were the main cause of the improvements.

Quite interestingly, the students’ scores on computation also improved — despite the reduced presence of computation in class because of the ramped-up levels of conceptual problems. We did fewer computational problems on the board and in group work, and yet their performance on raw computation improved! Again, I don’t think integration is easier than differentiation at this stage in the course, so I don’t think this improvement was because the material got easier. Maybe the last test put the fear of God into them and they started working outside of class more. I don’t know. But this does indicate to me that skill in computation is not strictly proportional to the amount of computation I do, or anybody else does, in class.

To overgeneralize for a second: Increased repetition on conceptual problems improves performance on those problems dramatically, while the corresponding reduction in time spent on computational exercises not only does not harm students’ performance on computation but might actually have something to do with improving it. If we math teachers can understand the implications of this possibility (or at least understand the extent to which this statement is true) we might be on to something big.

The scores on problem solving went two different directions. On the one hand, the median went up; but on the other hand the mean went down. And the middle 50% didn’t get any better on the top end and got worse on the bottom end. I’m still parsing that out. It could be the content itself this time; most of the actual problems in integration tend to take place near the end of the chapter, after the Fundamental Theorem and u-substitution, so the kinds of problems in this section were less than a week old for these students. But quite possibly the improvement in conceptual knowledge brought the median up on problem solving, despite the newness of the problems. Or maybe the differences aren’t even statistically significant.

What I take away from this is that if you want students to do well on non-routine problems, those problems have to occupy a central place in the class, and they have to be done not outside of class where there’s no domain expert to guide the students through them but in class. And likewise, we need not worry so much that we are “wasting precious class time” on group work on conceptual problems at the expense of individual computation skill. Students might do just fine on that stuff regardless, perhaps even better if they have enhanced conceptual understanding to support their computational skills.

It all goes back to support the inverted classroom model which I’ve been using in the MATLAB course, and now I’m wondering about its potential in calculus as well.

## MATLAB as a handout creator

One of the fringe benefits of having immersed myself in MATLAB for the last year (in preparation for teaching the Computer Tools for Problem Solving course) is that I’ve learned that MATLAB is an excellent all-purpose tool for preparing materials for my math classes. Here’s an example of something I just finished for a class tomorrow that I’m really pleased with.

I was needing to create a sequence of scatterplots of data for a handout in my Functions and Models class. The data are supposed to have varying degrees of linearity — some perfect/almost perfectly linear, some less so, some totally nonlinear — and having different directions, and the students are supposed to look at the data and rank the correlation coefficients in order of smallest to largest. (This is a standard activity in a statistics class as well.)

I could have just made up data with the right shape on Excel or hand-drawn the scatter plots, but whenever I do that, it looks made it up — not with the randomness that a real set of data, even if it’s strongly linear, would have. So instead, I thought I would take a basic linear function and throw varying degrees of noise into it to make it less linear.

I wrote this little function to generate noise:

function n = noise(degree, size)
n = degree*cos(2*pi*rand(1,size));


This just creates a vector of specified length (“size”) centered roughly around 0, and the bigger “degree” is the more wildly the numbers vary. (I’m sure there’s some built-in way to do this in MATLAB, but it probably took less time to write the function than it would have taken for me, the MATLAB neophyte, to look it up.)

Then I just made four linear functions and literally added in the noise for each, as well as a fifth function that was just spitting out 25 random numbers and a sixth that was a pure linear function with no noise. Then plot all of those in a 2×3 subplot. Here’s the code:

x = 1:25;
y_bigneg = -3*x+90 + noise(5,25);
y_smallneg = -5*x + 100 + noise(30,25);
y_bigpos = 3*x + 3 + noise(3,25);
y_smallpos = 3*x + 3 + noise(10,25);
subplot(2,3,1), scatter(x, y_bigpos)
subplot(2,3,2), scatter(x, y_smallneg)
subplot(2,3,3), scatter(x, y_smallpos)
subplot(2,3,4), scatter(x, y_bigneg)
subplot(2,3,5), scatter(x, rand(1,25))
subplot(2,3,6), scatter(x, 90-4*x)


Here’s the result, after going in and adding titles and removing the legends in the Plot Tools window:

That can then be saved as a PDF and embedded into a $\LaTeX$ document or just posted directly to Moodle for students to play with. All of that code above could easily be compacted into one big M-file with some modifications to let the user control the number of points and whatever else.

This is basic stuff, but it’s awfully handy for creating professional-looking documents and graphics for teaching mathematics. That’s an area where I’m finding MATLAB is highly underrated.

1 Comment

Filed under Calculus, Math, MATLAB, Problem Solving, Teaching, Technology

## Analyze, hack, create

One of these days I’ll get back to blogging about the mathematics courses I teach, which make up the vast majority of my work, but the MATLAB course continues to be the place where I am working the hardest, struggling the most, learning the biggest lessons about teaching, and finally having the greatest sense of reward. This week was particularly rewarding because I think I finally figured out a winning formula for teaching a large portion of this stuff.

This was the last in a three-week series on introduction to programming. We had worked with FOR loops already. I had planned to look at WHILE loops in the same week as FOR loops, then have the students play around with branching structures in week 2, then have them apply it to writing programs to do numerical integration week 3 for use in their Calculus II class in which most of the class is currently enrolled. But the FOR loop stuff went very roughly. So I moved the numerical integration stuff up a week and saved the entire remainder of looping and branching structures — WHILE loops, the IF-ELSEIF-ELSE structure, and SWITCH — for week 3.

I approached it like this.

The majority of their homework consisted of watching three videos: one on general programming in MATLAB, another on MATLAB loop structures in general, and a third on IF and SWITCH statements. That’s about 20 minutes of straight viewing; I told the students to budget an hour for these, since they’ll want to pause and rewind and work alongside the videos. Then, the majority of their homework was this M-file:

%% Script M-file for April 5 Prep/HW for CMP 150.
%
% For each block of code below, write a clear, English paragraph that
% explains what the code does. You can play with each block of code by
% removing the comment symbols and running this file. (You can "uncomment"
% lines by deleting the percent symbol or by highlighting the code you want
% and selecting Text > Uncomment from the menu above.)

%% Code example 1

x = input('Please enter in a number less than 100: ');
while x < 100
disp(x)
x = 2*x - 1;
end

%% Code example 2

x = input('Please enter in a number: ');
if x>=0
y = sqrt(x)
else
y = exp(x) - 1
end

%% Code example 3

value = input('Please enter in a whole number between 1 and 20: ');
switch value
case {2, 3, 5, 7, 11, 13, 17, 19}
disp('Your input is a prime number.')
case {1, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20}
disp('Your input is a composite number.')
otherwise
disp('I do not think you entered in a whole number between 1 and 20.')
end


In other words: Here’s a bunch of code. Write up a plain-English description of what everything is doing. That was their homework. (Here’s the full assignment.)

Then in class, we played a game. For each code sample, I asked, “What if I entered [fill in the blank] to this bit of code?” For example, for code sample #1, what would happen if I entered in 100? One student immediately said, “Nothing”. Another said “It would give you a ‘0’ because that’s what ‘100 < 100’ returns as in MATLAB.” Then I had them close their eyes. “How many say, ‘Nothing’?” Count the hands that go up. “How many say ‘0’?” Count those hands. Put the tally on the board. The result: 7 for “nothing”, 6 for “zero”. Instant discussion fodder.

(By the way, this would have been a perfect place for clickers. I’m working on that.)

Next I asked, “What would happen in code sample 1 if I put in a negative number?” One guy said: “I know! I did that, and the thing kept running and never stopped, and I had to unplug my computer!” So I showed them all Control-C; then asked, “Why did that [the failure of the program to stop] happen?” In no time at all — a high-order discussion about an important related topic to looping structures (avoiding infinite loops) that I had not even planned to bring up.

We played that game for 20 more minutes. Students were into it. They were coming up with their own cases. We tried entering in ‘Hi mom’ to code sample #1 and it actually gave something back. It was mysterious and entertaining and nerdy. They discovered that testing out extreme cases is not only important for understanding your code, it’s fun. And it was a lot better than lecturing.

The best thing is, when I got them finally into their lab problems, they were asking better questions. “I think I can do this program with a SWITCH statement, but could I make it better with an IF statement?” And: “I’ve got all the cases listed out here in my SWITCH statement, but I wonder if I could just use a vector or LINSPACE to list them out instead.

So that’s going to be my approach from here on:

1. Analyze: Look at someone else’s code and write out a complete, plain-English description of what every part of it is doing.
2. Hack: Take the same code and modify it, tweak it, rewrite it, throw extreme cases at it. This is the bridge between reading code and writing code.
3. Create: Write some code to do something new — now that you’ve learned the language from someone else’s use of it.

For all I know I could be totally reinventing 40-50 years of established best practices in computer science pedagogy. But it’s pretty exciting nonetheless.