Mathematica How can I prevent Table[] from evaluating its arguments each time?

  • Thread starter Thread starter matiasmorant
  • Start date Start date
  • Tags Tags
    Mathematica Table
AI Thread Summary
The discussion focuses on creating a Table[] in a programming context without evaluating its arguments each time. The user seeks to generate a table of squares, specifically {1^2, 2^2, 3^2, 4^2, 5^2, 6^2, 7^2, 8^2, 9^2, 10^2}, rather than the numerical results. Two approaches are presented: using the With function combined with Defer, and utilizing Superscript. The first method allows for easy copying and pasting while maintaining the desired format, which is highlighted as a significant advantage. The user expresses satisfaction with the solution provided.
matiasmorant
Messages
38
Reaction score
0
I want to make a Table[] but aI don't want this function to evaluate its argument each time. for example, I want to make the table {12,22,32,42,...}, instead of {1,4,9,16,...}


how?
 
Physics news on Phys.org
Two (out of many) possible approaches

In[1]:= Table[With[{nn=n},Defer[nn^2]],{n,1,10}]
Out[1]= {1^2,2^2,3^2,4^2,5^2,6^2,7^2,8^2,9^2,10^2}
In[2]:= Table[Superscript[n,2],{n,1,10}]
Out[2]= {1^2,2^2,3^2,4^2,5^2,6^2,7^2,8^2,9^2,10^2}

The advantage of the first one, is that if copied and pasted, it will evaluate as normal.
 
Thanks a lot, I could do what I wanted
 

Similar threads

Back
Top