Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.6K Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How can I combine -for- function with Grid

Posted 10 years ago

Hi, I have a function f. and I would like to print some values of it, but for the shake of better reading, I would like to print them in grid. My range is dynamic, hence I need to set a desired value, and then use a for to print it. To better illustrate what I need consider this

f[x_] := x^2;
Grid[{
  {1, f[1]},
  {2, f[2]}
  }, Frame -> All]

in this case I print for 1 and 2. What I need is to set an initial value lets say k, and print this grid for i=1 until k.

POSTED BY: Tom Zinger
3 Replies

Table is the most commonly used function for iterating over values:

Grid[Table[{i, f[i]}, {i, 1, 10}], Frame -> All]
POSTED BY: Sean Clarke
Posted 10 years ago

Thanks for your help. What if i need bivariate function? i,j,f[i,j]?

It doesn't seen to work...

Grid[Table[{i,j,f[i,j]},{i,1,2},{j,1,2}],Frame->All]
POSTED BY: Tom Zinger

Try:

f[i_, j_] := i + j^2
Grid[Table[f[i, j], {i, 1, 5}, {j, 1, 5}]]
TableForm[Table[f[i, j], {i, 1, 5}, {j, 1, 5}],TableHeadings -> Automatic]
POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard