Generalizing "for" Lists and Intervals

In Desmos, you can use ‘for’ to plot points or evaluate a variable for multiple values using a list or to graph a continuous curve with finite or infinite intervals. This feature allows you to generalize expressions to answer questions such as “What would be the path of this object if it followed a list of discrete points?” and “What if it followed a curve?”

Using 'for' to Graph Points

If we want to graph three points along the line \(x=1\), we could individually plot \((1,1)\), \((2,1\)), and \((3,1)\). ‘For’ gives us a more succinct option within a single expression line. Using ‘for’, we can graph the same three points by typing \((a,1)\) for \(a=[1,2,3]\). If we change our point to \((a,a)\) for \(a=[1,2,3]\), then we will see three points in a line: \((1,1)\), \((2,2)\), and \((3,3)\). Since there is only one list, the calculator uses each value in the list exactly once.

Wondering how to graph a 3x3 grid using ‘for’? To graph a grid, try \((a,b)\) for \(a=[1,2,3], b=[1,2,3]\). ‘For’ uses the Cartesian product, generating every possible ordered pair where the x-value is from list \(a\) and the y-value is from list \(b\). With only one list, though, the computer uses each value in the list exactly once.

Try it! Open the graph to the right and try it out. How would you create a larger grid?

Image of points being plotted using a list and the for function.

Using ‘for’ to Graph Line Segments and Curves

With lists, we can plot points closer and closer together by reducing the interval between the numbers in our list. Using our example from above, if we want more than three points to appear, we can shorten the distance between the numbers in our list. For example, graphing \((a,a)\) for \(a=[1,1.1…3]\) will plot 21 points of the form \((a,a)\) that are 0.1 units apart. We could plot even closer points if we change the list to something like \(a=[1,1.01…3]\), which gives us 201 points of the form \((a,a)\) that are now 0.01 units apart. We could keep reducing the distance to create the appearance of a solid line. Or, we can graph a line using ‘for’ and an interval. For example, \((a,a)\) for \(1\le a\le3\) will graph a line segment of all the points of the form \((a,a)\) between \(1\) and \(3\). To graph the full line, you can graph \((a,a)\) for \(-\infty\le a\le\infty\). This will show you all the points that satisfy the condition where the x-value is equal to the y-value.

Try it! Open the graph to the right and try it out. What other lines can you graph using `for`?

Image of a line being plotted using a lists, the for function, and intervals.

Generalizing the path of the vertex of a parabola

'For' allows you to map an expression across a list or interval. Lists are a powerful tool to quickly work with multiple values (or elements) at once, while an interval captures all of the values that fall within the bounds you set.

Let's reason about the path that the vertex of a parabola in standard form would follow. Starting with \(f(x)=ax^2+bx+c\), our parabola will have a vertex \(V=(-\frac{b}{2a},f(-\frac{b}{2a}))\).

We'll start by looking at how the value of \(b\) affects our parabola. In the example, you'll see sliders at \(a=1\), \(b=0\), and \(c=1\).

We can start by choosing values we want to test for \(b\). For example, we can set \(b=[-5...5]\), an 11 element list with all of the integers from \(-5\) to \(5\). Then, if we type \(V\) for \(b=[-5...5]\), we will see the 11 different places the vertex would be for each of those \(b\) values.

GIF showing the path a generalized vertex follows as seen in the example graph.

To see the path the vertex will follow for all values between \(-5\) and \(5\), type \(V\) for \(-5 \le b \le 5\). We can verify this by editing the inputs beneath the expression from our \(b\) slider to \(-5\) to \(5\) and then playing the slider to watch the vertex of our parabola follow the path we graphed above.

Try it! Open the graph below and try it out. What else can you generalize with 'for'? How does playing with the sliders for \(a\), \(b\), and \(c\) change the graph?

Generalizing from lists of points to parametrics curves and surfaces

One way to start building up an intuition for parametric equations is to visualize the path over a list of discrete points before visualizing that same path as a continuous curve within an interval.

Here, we’ll use the parametric equation of a unit circle as an example: \((\cos(t), \sin(t))\). While we typically need to use the special parameter \(t\) to graph a parametric curve, we can now define the interval inline for any parameter we want. Let’s use \(c\) since the curve will represent the circumference of a circle.

Starting with a list of values \(c= [0, \frac{\pi}{4}…2\pi]\), let’s plot \((\cos(c), \sin(c))\) for \(c = [0, \frac{\pi}{4}…2\pi]\) to visualize 8 equally spaced points around the unit circle.

With lists, we can plot points closer and closer together lying along a curve by increasing the number of points in our list. To take this one step further and graph a continuous curve, we can use an interval. Try typing \((\cos(c), \sin(c))\) for \(0 \le c \le 2\pi\) to graph the continuous unit circle.

GIF of the example graph turning on the list of points, then an interval of points, then the parametric surface.

Last, let’s consider graphing a 3D surface. In this case, we will need a \(z\)-coordinate. For a cylinder with its base on the \(XY\) plane and a height of 3, we need our unit circle for all possible \(z\) values from 0 to 3. To do so, we introduce a new variable for height, \(h\). Try typing \((\cos(c), \sin(c))\) for \(0 \le c \le 2\pi, 0 \le h \le 3\).

Try it! Open the graph below and try it out. Can you trace a circle around the top of the cylinder? How would you create a cylinder below the \(XY\) plane?