4

Here is a PDE example, adapted from Wolfram Documentation:

bsol = First[NDSolve[{D[u[x, t], t] ==
0.1*D[u[x, t], x, x] - u[x, t] D[u[x, t], x],
u[x, 0] == 1 - x^2, u[-1, t] == 0, u[1, t] == 0}, 
u, {x, -1, 1}, {t, 0, 4}]]

In my work, I need to change the initial condition (IC) to a smooth random function, but with endpoints located at $u(-1, 0) = u(1, 0) = 0$, which should be suitable for being an IC of the PDE in NDSolve. To this end, I use

ini[x_] = BSplineFunction[RandomReal[{-1, 1}, 10], SplineClosed -> True][(x + 1)/2];

After plotting,

Plot[ini[x], {x, -1, 1}]

something like this

we find that the endpoints are not satisfied with $u(-1, 0) = u(1, 0) = 0$. But I cannot come up with an simple way to do this. Given a BSplineFunction through the two end-points, I specified the endpoints as follows:

Join[{{-1, 0}}, RandomReal[{-1, 1}, 10], {{1, 0}}]

but it doesn't work. I think it's almost there... I really hope somebody can help me out. Thank you very much!

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
lxy
  • 165
  • 5
  • 19
  • Is the first coordinate in the Join correct? – user21 Oct 15 '18 at 12:25
  • Try this: BSplineFunction[ Join[{0.}, RandomReal[{-1, 1}, n - 1], {0.}], SplineClosed -> True ] – Henrik Schumacher Oct 15 '18 at 12:34
  • I think SplineClosed -> True somehow destroys your zero boundary condition. With SplineClosed -> False it works as Henrik showed. – Thies Heidecke Oct 15 '18 at 12:41
  • Thank you for the correct me @user21, corrected it. – lxy Oct 15 '18 at 13:03
  • Thanks @Thies Heidecke by SplineClosed -> True I just want to make the two end-points the same... see @ Henrik Schumacher also suggest SplineClosed -> True. – lxy Oct 15 '18 at 13:05
  • @Henrik Schumacher Could you explain a little what is n, why n-1, and why {0.} works? Thanks you very much! I try ini[x_] = BSplineFunction[Join[{0.}, RandomReal[{-1, 1}, 11-1], {0.}], SplineClosed -> True][(x + 1)/2]. However, both ini[-1] and ini[1] close to zero but not exactly. – lxy Oct 15 '18 at 13:11
  • That's why i said try SpineClosed -> False, then it works. The manually added zero endpoints will make sure they match zero, SpineClosed -> True is for periodic boundary conditions which you don't need here. – Thies Heidecke Oct 15 '18 at 13:24
  • Here is another suggestion for you to consider, which I can elaborate later on when I can borrow a computer. Take any function satisfying your endpoint conditions (e.g. an InterpolatingPolynomial[]), and then perturb it with 1D Perlin noise, just like what I did in this answer. – J. M.'s missing motivation Oct 15 '18 at 13:37
  • A second possibility is to use BrownianBridgeProcess[] with RandomFunction[] to generate a bunch of points, which you can then feed to a cubic periodic spline. – J. M.'s missing motivation Oct 15 '18 at 13:42

1 Answers1

3

Let me expand on one of the comments I gave earlier.

As I mentioned, one can use BrownianBridgeProcess[] with RandomFunction[] to generate a set of points that can then be passed to Interpolation[] to get a random smooth function with the desired endpoint conditions:

BlockRandom[(* for reproducibility *)
            SeedRandom["somefunction", Method -> "MersenneTwister"];
            jsxs = Interpolation[MapAt[Rescale[#, {0, 2}, {-1, 1}] &, 
                                       RandomFunction[BrownianBridgeProcess[0, 2],
                                                      {0, 2, 1/32}]["Path"], {All, 1}],
                                 Method -> "Spline"]];

Plot the random function:

Plot[jsxs[x], {x, -1, 1}]

random function

Use it in the PDE:

sol = NDSolveValue[{D[u[x, t], t] == 0.1 D[u[x, t], x, x] - u[x, t] D[u[x, t], x],
                    u[x, 0] == jsxs[x], u[-1, t] == 0, u[1, t] == 0}, u,
                   {x, -1, 1}, {t, 0, 2}];

Plot3D[sol[x, t], {x, -1, 1}, {t, 0, 2}, BoxRatios -> Automatic, PlotRange -> All]

PDE solution with smooth random BC

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574