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!
Join
correct? $\endgroup$BSplineFunction[ Join[{0.}, RandomReal[{-1, 1}, n - 1], {0.}], SplineClosed -> True ]
$\endgroup$SplineClosed -> True
somehow destroys your zero boundary condition. WithSplineClosed -> False
it works as Henrik showed. $\endgroup$SplineClosed -> True
I just want to make the two end-points the same... see @ Henrik Schumacher also suggestSplineClosed -> True
. $\endgroup$