# core language – Create list of functions, domains, and iterate over (compare to Python code)

In Mathematica, I want to do a mass export of many different animated plots of specific functions with different domains. Because I don’t necessarily want the plots to always have exactly the same range for each graph, (for example, -1 to 1 on X and -1 to 1 on Y), I want to manually specify this value for each function I create.

For example, in Python, I could do something like this:

``````def g1(x):
return x*x + 1
x_range1 = (-2, 2)
y_range1 = (0, 4)

def g2(x):
return math.log(x)
x_range2 = (0, 8)
y_range2 = (-4, 4)

def g3(x):
return 2*math.cos(x)
x_range3 = (-4, 4)
y_range3 = (-4, 4)

func_list = ((eval(f'g{ii}'), eval(f'x_range{ii}'), eval(f'y_range{ii}')) for ii in range(1, 3 + 1))

for function, x_range, y_range in func_list:
print(function, x_range, y_range)
``````

And I would get the output:

``````<function g1 at 0x000002063F0EF670> (-2, 2) (0, 4)
<function g2 at 0x000002063F0EF700> (0, 8) (-4, 4)
<function g3 at 0x000002063F0EF790> (-4, 4) (-4, 4)
``````

Basically, I’m able to easily create an arbitrarily long list of functions and domains and then access them however I need to in the for loop. I’m sure that something similar is possible in Mathematica, I just don’t know the syntax.

I could just create a list of single plot objects, I suppose, but there might be other aspects that I want to be the same between all of the graphs (such as the line color, axis font, etc.). So really it would be ideal if I could do it very similar to the way I did in Python where I only specify the aspects specific to each function $$g_i$$ and then force those into a plot object within the for loop so that only the function and range changes, but not the other arguments.

I don’t know if Mathematica can do what I’m looking for, ideally in a way similar to what I presented in the Python code above. If so, does anybody have an example?

Posted on Categories Articles