# 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?”

'For' allows you to map a point or an expression across a list or interval. Lists are a powerful tool to quickly work with multiple values (or elements) simultaneously, while intervals capture all of the values that fall within the specified bounds.

## Using 'for' to graph points

If you want to graph three points along the line $$x=1$$, you could individually plot $$(1,1)$$, $$(2,1$$), and $$(3,1)$$. ‘For’ gives a more succinct option within a single expression line. Using ‘for,’ graph the same three points by typing $$(a,1)$$ for $$a=[1,2,3]$$. Changing the point to $$(a,a)$$ for $$a=[1,2,3]$$ will plot three points along a line: $$(1,1)$$, $$(2,2)$$, and $$(3,3)$$.

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]$$. In this case, ‘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$$.

Try it! Open the graph by clicking on the image and try it out. How would you create a 4x3 grid using the lists $$a$$ and $$b$$?

## Using ‘for’ to graph line segments and curves

With lists, you can plot points closer and closer together by reducing the interval between the numbers.

Using the example from above, if you want more than three points to appear, shorten the distance between the numbers in the 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. To plot even closer points, change the list to something like $$a=[1,1.01…3]$$, which would display 201 points of the form $$(a,a)$$ that are 0.01 units apart.

You can keep reducing the distance to create the appearance of a solid line. Or, you 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, type $$(a,a)$$ for $$-\infty\le a\le\infty$$. This will show all the points that satisfy the condition where the $$x$$-value is equal to the $$y$$-value.

Try it! Open the graph by clicking on the image and try it out. What other lines can you graph using 'for'?

## Generalizing the path of the vertex of a parabola

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.

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? https://www.desmos.com/calculator/ky2jk9ddui

## 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. For example, the parametric equation of a unit circle is $$(\cos(t), \sin(t))$$. While the special parameter t can be used to graph this parametric curve, the interval can also be defined inline using any parameter to represent the circumference of a circle.

Starting with a list of values $$c= [0, \frac{\pi}{4}…2\pi]$$, 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, plot points closer and closer together along the curve by increasing the number of elements in the list. To take this one step further, graph a continuous curve with an interval. Try typing $$(\cos(c), \sin(c))$$ for $$0 \le c \le 2\pi$$ to graph the continuous unit circle.

Last, consider graphing a 3D surface. In this case, a z-coordinate is needed. For a cylinder with its base on the x-y plane and a height of 3, the unit circle is graphed for all possible z values from 0 to 3. To graph this, introduce a new variable for height, like h. Try typing $$(\cos(c), \sin(c))$$ for $$0 \le c \le2pi$$, $$0 \le h \le 3$$.

Try it! Open the graph by clicking on the GIF 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?