Using Desmos: How to Use 'for' and 'with'
Created: 2025/3/15

Desmos Graphing Calculator lets you express equations more flexibly using for and with.

for

The for keyword is primarily used in two scenarios: parametric representation and iterating through elements of a list.

Parametric Representation

In Desmos, you can use the variable tt to create parametric graphs. However, withfor, you can use any variable as a parameter.

1
(1,t)(1,t)
2
(2,a) for 0a1(2,a)\ \mathrm{for}\ 0 ≤ a ≤ 1

tt is often used to represent time in physics, making it particularly useful in such cases.

Keep in mind that the parameter's range must always be explicitly defined, such as 1s61 ≤ s ≤ 6. If you want to represent 1s1 ≤ s, you need to use infinity and write 1s<1 ≤ s < ∞.

Interestingly, when using tt for parametric representation, you can't define an infinite domain like this. This is one of the advantages of using for.

Iterating Through List Elements

You can create graphs by iterating through the elements of a list like this:

1
y=ax for a=[1,2,3]y = ax\ \mathrm{for}\ a = [1, 2, 3]

You can also use multiple lists. In this case, all combinations of elements are iterated through.

1
(x,y) for x=[1,2,3,4],y=[2,3,4](x, y)\ \mathrm{for}\ x = [1, 2, 3, 4], y = [2, 3, 4]

You can even generate lists using list comprehensions, as shown below:

1
[ 2i for i=[ 1,2,4 ] ] (=[ 2,4,8 ])[\ 2i\ \mathrm{for}\ i=[\ 1,2,4\ ]\ ]\ (=[\ 2,4,8\ ])
2
[ 1 for i=[ 1,2,...,100 ] ] (=[ 1,1,...,1100 ])[\ 1\ \mathrm{for}\ i=[\ 1,2,...,100\ ]\ ]\ (=[\ \underbrace{1,1,...,1}_{100}\ ])

For more details on using lists, check out the following article:

Using Desmos: Working with Lists

with

The with keyword allows you to define the value of a variable. It has two main applications.

Substituting Variable Values

You can replace the value of an already defined variable within a specific expression.

For example:

1
a=5a = 5
2
y=axy = ax

This draws y=5xy = 5x, but:

1
a=5a = 5
2
y=ax with a=10y = ax\ \mathrm{with}\ a = 10

This draws y=10xy = 10x.

Defining Variables Locally

Normally, when you define a=5a = 5, aa can be referenced in all expressions. However:

1
y=ax with a=5y = ax\ \mathrm{with}\ a = 5

In this case, aa cannot be referenced from other expressions.

While this might seem limiting, it helps prevent naming conflicts when working with many variables.

You can achieve the same result by using functions:

1
f(x,a)=axf(x, a) = ax
2
y=f(x,5)y = f(x, 5)
SHARE
Images are created with the Desmos Graphing Calculator, used with permission from Desmos Studio PBC.
© 2024 UNS Physics. All Rights Reserved.