3
$\begingroup$

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!

$\endgroup$
  • $\begingroup$ Is the first coordinate in the Join correct? $\endgroup$ – user21 Oct 15 '18 at 12:25
  • $\begingroup$ Try this: BSplineFunction[ Join[{0.}, RandomReal[{-1, 1}, n - 1], {0.}], SplineClosed -> True ] $\endgroup$ – Henrik Schumacher Oct 15 '18 at 12:34
  • $\begingroup$ I think SplineClosed -> True somehow destroys your zero boundary condition. With SplineClosed -> False it works as Henrik showed. $\endgroup$ – Thies Heidecke Oct 15 '18 at 12:41
  • $\begingroup$ Thank you for the correct me @user21, corrected it. $\endgroup$ – jsxs Oct 15 '18 at 13:03
  • $\begingroup$ Thanks @Thies Heidecke by SplineClosed -> True I just want to make the two end-points the same... see @ Henrik Schumacher also suggest SplineClosed -> True. $\endgroup$ – jsxs Oct 15 '18 at 13:05
1
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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