1
$\begingroup$

The code is like:

f[x_,y_]:=x^2+y^2;
Table[f[x,y],{x,{10^Range[-3,2]}},{y,0,1,1}];

The table is not working now. It shows:

The second part of {} doesn't exist.
$\endgroup$
2
  • $\begingroup$ @cvgmt Sorry,but this can't work.... I type this wrong... Your version can't work,too. $\endgroup$ Apr 5, 2022 at 11:05
  • $\begingroup$ The code in your question already works fine. Have you tried removing the semicolon at the end of the Table statement? That will show you the output. If that output is not what you want, then please give an example of an acceptable result as well. $\endgroup$
    – MarcoB
    Apr 5, 2022 at 12:38

1 Answer 1

4
$\begingroup$

Range[] returns a list, so you shouldn't wrap it in {}:

f[x_,y_]:=x^2+y^2;
Table[f[x,y],{x,10^Range[-3,2]},{y,0,1,1}];

You can also adjust increments if you need more number in-between, for example:

f[x_, y_] := x^2 + y^2;
TableForm[
 Flatten[
  Table[{x, y, f[x, y]}, {x, 10^Range[-3, 2, 0.5]}, {y, 0, 1, 0.5}]
  , 1]
 , TableHeadings -> {None, {"x", "y", "f[x,y]"}}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.