# Smooth initial data

I need something that produce pseudorandom smooth initial data for modelling phase separation equations (Cahn-Hilliard and simular).

Generator code for now:

bounds = 200;
func = Interpolation@
Flatten[Table[{{x, y},
RandomReal[{-0.5, +0.5}]}, {x, -bounds, +bounds}, {y, -bounds, +bounds}], 1];
DensityPlot[func[x, y], {x, -200, 200}, {y, -200, 200},
ColorFunction -> "TemperatureMap", PlotLegends -> Automatic]

And typical output with bounds = 200
But it have interpolation artifacts which leads to system instability in future (i using weak boundary condition).

How to generate smooth initial noise with dispersion that decreases near bounds?

• Why are the parts at the corners artifacts? They don't look any different than the rest of the plot. Do you need the data to go smoothly to zero at the edges of the bounds, or do you want the values at +bounds and -bounds to be equal? Jan 27, 2016 at 13:17
• What about generating a certain number of random amplitudes, and forming the noise as a Fourier series with those amplitudes? Jan 27, 2016 at 13:52
• Look's nice but difficult consider my knowledge of Mathematica. Can you give me some reference or examples? @JasonB not, it's not required. Jan 27, 2016 at 14:05
• What do you mean by with dispersion that decreases near bounds? Jan 27, 2016 at 14:06
• @Dr.belisarius That random amplitude decreases near edges. Jan 27, 2016 at 14:08

You can just multiply the random numbers by a windowing function that does go to zero in the way you want. One choice is a super-Gaussian, it's like a smooth version of a square windowing function (with n=6 below, but you can choose other values

Plot[Exp[-(x/120)^6], {x, -210, 210}, PlotRange -> {0, 1}]

Here is the initial data,

bounds = 200;
width = 120;
func = Interpolation[
Flatten[Table[{{x, y},
Exp[-(x/width)^4 - (y/
width)^4] RandomReal[{-0.5, +0.5}]}, {x, -bounds, +bounds}, \
{y, -bounds, +bounds}], 1]];
DensityPlot[func[x, y], {x, -200, 200}, {y, -200, 200},
ColorFunction -> "TemperatureMap", PlotLegends -> Automatic,
PlotRange -> All]

By the way, to really get an idea of the data, you need to increase the PlotPoints

DensityPlot[func[x, y], {x, -200, 200}, {y, -200, 200},
ColorFunction -> "TemperatureMap", PlotLegends -> Automatic,
PlotRange -> All, PlotPoints -> 100]

Edit If you write a code that makes something similar to this gif from Wikipedia, I'd love to see it.

• I'm interesting to you GIF,If you can make it.you can answer my question that I have posts just now,please.
– yode
Feb 14, 2016 at 6:49

In a simplified 1D version my idea may look as follows. Here are two lists of the amplitudes, that I limited by 10 terms:

lst1 = RandomReal[{-1, 1}, 10];
lst2 = RandomReal[{-1, 1}, 10];

Here are the arbitrary functions defined as the Fourier-polynomials with the above amplitudes:

y1[x_] := Sum[lst1[[i]]*Sin[x*i], {i, 1, Length[lst1]}]
y2[x_] := Sum[lst2[[i]]*Sin[x*i], {i, 1, Length[lst2]}]

Let us now draw them:

Generalization for the 2D case is straightforward.

Have fun!

bounds = 200;
f[{x_, y_}] := CDF[GammaDistribution[4, 2], 15 Rescale[
Min@Outer[Abs[Subtract@##] &, {x, y}, {bounds, -bounds}], {0,
bounds}, {0, 10}]]/2 // N
func = Interpolation@Flatten[Table[{{x, y}, RandomReal[{-#, +#}] &@
f[{x, y}]}, {x, -bounds, +bounds}, {y, -bounds, +bounds}], 1];
DensityPlot[func[x, y], {x, -bounds, bounds}, {y, -bounds, bounds},
ColorFunction -> "TemperatureMap", PlotLegends -> Automatic]

Here you can see the "dampening" at the boundaries:

Plot[func[x, 0], {x, bounds 9/10, bounds}]