# Generate a smooth random function (2D curve) with endpoints specification?

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

• 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. – jsxs 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. – jsxs Oct 15 '18 at 13:05

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