Solution

The Module command can be used to wrap a set of commands into a single function. The first argument is the declaration of any possible local variables.

In[55]:=

nmax = 100 ; Clear[x, y, f, n, z, n0]

f[x_, y_] := Module[{n}, n = 0 ; For[z0 = 0 ; z = 0, Norm[z] <2&&n<nmax, z0 = z, z = z0^2 + x + I y ; n ++] ; Return[n]] ;

Plot3D[f[x, y], {x, -2, 1}, {y, -1, 1}, PlotPoints100]

[Graphics:../HTMLFiles/ex08_solutions_116.gif]

Out[57]=

⁃SurfaceGraphics⁃


Created by Mathematica  (April 10, 2007) Valid XHTML 1.1!