I type the following code in Mathematica 11:
For[n = 1, n <= 3, n++,
RegionPlot[x^2 + y^3 < n, {x, -2, 2}, {y, -2, 2}]
]
Then I press Shift+Enter, but Mathematica does not output any figures. Where is the problem? Thanks in advance.
It depends on what your aim. If it is just to 'print' 3 graphics:
For[n = 1, n <= 3, n++,
Print@RegionPlot[x^2 + y^3 < n, {x, -2, 2}, {y, -2, 2}]]
If you want an object you can use and refer to:
f[x_, y_] := x^2 + y^3
rps=RegionPlot[f[x, y] < #, {x, -2, 2}, {y, -2, 2}] & /@ Range[3]
This is also a useful link with respect to loops in Mathematica.
For fun
Manipulate[
RegionPlot[x^2 + y^3 < n, {x, -2, 2}, {y, -2, 2}],
{n, 1, 3, 1}
]
Graphics
expressions rather than displaying them as side-effects. See (47123). You could addPrint
but generally a better method is to replaceFor
withTable
:Table[RegionPlot[x^2 + y^3 < n, {x, -2, 2}, {y, -2, 2}], {n, 1, 3}]
. You can further format that output withColumn
orGraphicsColumn
as desired, or animate it withListAnimate
. $\endgroup$