Given
Table[n^i,{n,10},{i,10}]
what needs to be done so that the expression being evaluated "n^i=" will appear for every element. For instance for the 1st element it would be 1^1 =1 and for the last element it would be 10^10=100000000
Table[With[{i = i, n = n}, PromptForm[Defer[n^i], n^i]], {n, 5}, {i, 5}]
{{1^1 = 1, 1^2 = 1, 1^3 = 1, 1^4 = 1, 1^5 = 1}, {2^1 = 2, 2^2 = 4, 2^3 = 8, 2^4 = 16, 2^5 = 32}, {3^1 = 3, 3^2 = 9, 3^3 = 27, 3^4 = 81, 3^5 = 243}, {4^1 = 4, 4^2 = 16, 4^3 = 64, 4^4 = 256, 4^5 = 1024}, {5^1 = 5, 5^2 = 25, 5^3 = 125, 5^4 = 625, 5^5 = 3125}}
TableForm @ %
Note: PromptForm
is still undocumented. It produces output similar to Row
with separator " = "
.
PromptForm[foo, bar]
Row[{foo, " = ", bar}]
Alternative methods:
TableForm @ Array[PromptForm[Defer[#^#2], #^#2] &, {5, 5}]
TableForm @ Outer[PromptForm[Defer[#^#2], #^#2] &, Range @ 5 , Range @ 5]
same picture
TableForm @ Array[Row[{Inactivate[Power @ ##], Power @ ##}, " = "] &, {5, 5}]
TableForm @ Outer[Row[{Inactivate[Power@##], Power@##}, " = "]&, Range @ 5, Range @ 5]
same picture
I would use Row
:
Grid[
Table[
Row[{n, "^", i, " = ", n^i}]
,
{n, 10}
,
{i, 10}
]
,
Alignment -> "=",
Frame -> All,
FrameStyle -> LightGray
]