5
$\begingroup$

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 Interpolated initial data
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?

$\endgroup$
5
  • $\begingroup$ 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? $\endgroup$
    – Jason B.
    Jan 27, 2016 at 13:17
  • 1
    $\begingroup$ What about generating a certain number of random amplitudes, and forming the noise as a Fourier series with those amplitudes? $\endgroup$ Jan 27, 2016 at 13:52
  • $\begingroup$ Look's nice but difficult consider my knowledge of Mathematica. Can you give me some reference or examples? @JasonB not, it's not required. $\endgroup$
    – K. Lonhus
    Jan 27, 2016 at 14:05
  • $\begingroup$ What do you mean by with dispersion that decreases near bounds? $\endgroup$ Jan 27, 2016 at 14:06
  • $\begingroup$ @Dr.belisarius That random amplitude decreases near edges. $\endgroup$
    – K. Lonhus
    Jan 27, 2016 at 14:08

3 Answers 3

4
$\begingroup$

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}]

enter image description here

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]

enter image description here

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]

enter image description here

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

enter image description here

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

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:

enter image description here

Generalization for the 2D case is straightforward.

Have fun!

$\endgroup$
2
$\begingroup$
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]

Mathematica graphics

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

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

Mathematica graphics

$\endgroup$
0

Your Answer

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

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