The Stack Overflow podcast is back! Listen to an interview with our new CEO.

4 deleted 150 characters in body; edited tags

1 + 0.05 rand(x,y) Here randrand is a pseudorandom function distributed in the interval (-1,1). This surface represents a random disturbance that I would like to use as an initial condition for PDEs in NDSolve.

L = 100;
Plot3D[
1 - 0.05 (Cos[2 \[Pi]π x/L] + Sin[2 \[Pi]π x/L]) Cos[
2Cos[2 \[Pi]π y/L] RandomReal[],
{x, 0, L},
{y, 0, L}
]


Obviously, this is wrong as this still retains the underlying Cos/Sin curve. How should I go about creating a random disturbance. ? $$\delta\varepsilon\pi$$

$HistoryLength = 0; Needs["VectorAnalysis"] Needs["DifferentialEquationsInterpolatingFunctionAnatomy"]; Clear[Eq0, EvapThickFilm, h, Bo, \[Epsilon]ε, K1, \[Delta], Bi, m, r] Eq0[h_, {Bo_, \[Epsilon]_ε_, K1_, \[Delta]_δ_, Bi_, m_, r_}] := \!$$\*SubscriptBox[\(\[PartialD]$$D[h, $$t$$]h\)t] + Div[-h^3 Bo Grad[h] + h^3 Grad[Laplacian[h]] + (\[Delta]δ h^3)/(Bi h + K1)^3 Grad[h] + m (h/(K1 + Bi h))^2 Grad[h]] + \[Epsilon]ε/( Bi h + K1) + (r) D[D[(h^2/(K1 + Bi h)), x] h^3, x] == 0; SetCoordinates[Cartesian[x, y, z]]; EvapThickFilm[Bo_, \[Epsilon]_ε_, K1_, \[Delta]_δ_, Bi_, m_, r_] := Eq0[h[x, y, t], {Bo, \[Epsilon]ε, K1, \[Delta]δ, Bi, m, r}]; TraditionalForm[ EvapThickFilm[Bo, \[Epsilon]ε, K1, \[Delta]δ, Bi, m, r]]; L = 2*92.389; TMax = 3100*100; Off[NDSolve::mxsst]; Clear[Kvar]; Kvar[t_] := Piecewise[{{1, t <= 1}, {2, t > 1}}] (*Ktemp* Ktemp = Array[0.001+0001 + 0.001#^2&001 #^2 &,13]* 13] *) hSol = h /. NDSolve[{ (*Bo,\[Epsilon]ε,K1,\[Delta]δ,Bi,m,r*) EvapThickFilm[0.003, 0, 1, 0, 1, 0.025, 0], h[0, y, t] == h[L, y, t], h[x, 0, t] == h[x, L, t], (*h[x,y,0] == 1.1+Cos[x] Sin[2y] *) h[x, y, 0] == BSplineFunction[RandomReal[1, {30, 30, 1}]] }, h, {x, 0, L}, {y, 0, L}, {t, 0, TMax}, Method -> {"BDF", "MaxDifferenceOrder" -> 1}, MaxStepFraction -> 1/50 ][[1]]  With the BSplineB-spline as suggested by Vitaliy Kaurov in the answer below, I have the following error: 1 + 0.05 rand(x,y) Here rand is a pseudorandom function distributed in the interval (-1,1). This surface represents a random disturbance that I would like to use as an initial condition for PDEs in NDSolve. L = 100; Plot3D[ 1 - 0.05 (Cos[2 \[Pi] x/L] + Sin[2 \[Pi] x/L]) Cos[ 2 \[Pi] y/L] RandomReal[], {x, 0, L}, {y, 0, L} ]  Obviously this is wrong as this still retains the underlying Cos/Sin curve. How should I go about creating a random disturbance. $HistoryLength = 0;
Needs["VectorAnalysis"]
Needs["DifferentialEquationsInterpolatingFunctionAnatomy"];
Clear[Eq0, EvapThickFilm, h, Bo, \[Epsilon], K1, \[Delta], Bi, m, r]
Eq0[h_, {Bo_, \[Epsilon]_, K1_, \[Delta]_, Bi_, m_, r_}] := \!$$\*SubscriptBox[\(\[PartialD]$$, $$t$$]h\) +
m (h/(K1 + Bi h))^2 Grad[h]] + \[Epsilon]/(
Bi h + K1) + (r) D[D[(h^2/(K1 + Bi h)), x] h^3, x] == 0;
SetCoordinates[Cartesian[x, y, z]];
EvapThickFilm[Bo_, \[Epsilon]_, K1_, \[Delta]_, Bi_, m_, r_] :=
Eq0[h[x, y, t], {Bo, \[Epsilon], K1, \[Delta], Bi, m, r}];
EvapThickFilm[Bo, \[Epsilon], K1, \[Delta], Bi, m, r]];

L = 2*92.389; TMax = 3100*100;
Off[NDSolve::mxsst];
Clear[Kvar];
Kvar[t_] :=  Piecewise[{{1, t <= 1}, {2, t > 1}}]
(*Ktemp = Array[0.001+0.001#^2&,13]*)
hSol = h /. NDSolve[{
(*Bo,\[Epsilon],K1,\[Delta],Bi,m,r*)

EvapThickFilm[0.003, 0, 1, 0, 1, 0.025, 0],
h[0, y, t] == h[L, y, t],
h[x, 0, t] == h[x, L, t],
(*h[x,y,0] == 1.1+Cos[x] Sin[2y] *)

h[x, y, 0] == BSplineFunction[RandomReal[1, {30, 30, 1}]]
},
h,
{x, 0, L},
{y, 0, L},
{t, 0, TMax},
Method -> {"BDF", "MaxDifferenceOrder" -> 1},
MaxStepFraction -> 1/50
][[1]]


With the BSpline as suggested by Vitaliy Kaurov in the answer below, I have the following error:

1 + 0.05 rand(x,y) Here rand is a pseudorandom function distributed in the interval (-1,1). This surface represents a random disturbance that I would like to use as an initial condition for PDEs in NDSolve.

L = 100;
Plot3D[
1 - 0.05 (Cos[2 π x/L] + Sin[2 π x/L]) Cos[2 π y/L] RandomReal[],
{x, 0, L}, {y, 0, L}
]


Obviously, this is wrong as this still retains the underlying Cos/Sin curve. How should I go about creating a random disturbance? $$\delta\varepsilon\pi$$

$HistoryLength = 0; Needs["VectorAnalysis"] Needs["DifferentialEquationsInterpolatingFunctionAnatomy"]; Clear[Eq0, EvapThickFilm, h, Bo, ε, K1, \[Delta], Bi, m, r] Eq0[h_, {Bo_, ε_, K1_, δ_, Bi_, m_, r_}] := D[h, t] + Div[-h^3 Bo Grad[h] + h^3 Grad[Laplacian[h]] + (δ h^3)/(Bi h + K1)^3 Grad[h] + m (h/(K1 + Bi h))^2 Grad[h]] + ε/( Bi h + K1) + (r) D[D[(h^2/(K1 + Bi h)), x] h^3, x] == 0; SetCoordinates[Cartesian[x, y, z]]; EvapThickFilm[Bo_, ε_, K1_, δ_, Bi_, m_, r_] := Eq0[h[x, y, t], {Bo, ε, K1, δ, Bi, m, r}]; TraditionalForm[ EvapThickFilm[Bo, ε, K1, δ, Bi, m, r]]; L = 2*92.389; TMax = 3100*100; Off[NDSolve::mxsst]; Clear[Kvar]; Kvar[t_] := Piecewise[{{1, t <= 1}, {2, t > 1}}] (* Ktemp = Array[0.001 + 0.001 #^2 &, 13] *) hSol = h /. NDSolve[{ (*Bo,ε,K1,δ,Bi,m,r*) EvapThickFilm[0.003, 0, 1, 0, 1, 0.025, 0], h[0, y, t] == h[L, y, t], h[x, 0, t] == h[x, L, t], (*h[x,y,0] == 1.1+Cos[x] Sin[2y] *) h[x, y, 0] == BSplineFunction[RandomReal[1, {30, 30, 1}]] }, h, {x, 0, L}, {y, 0, L}, {t, 0, TMax}, Method -> {"BDF", "MaxDifferenceOrder" -> 1}, MaxStepFraction -> 1/50 ][[1]]  With the B-spline as suggested by Vitaliy Kaurov in the answer below, I have the following error: 3 added 73 characters in body NDSolve::deqnndnum: Equation or list of equations expected instead ofEncountered non-numerical value for a derivative at t EvapThickFilm[0== 0.003,. >> ReplaceAll::reps: {(h^(0,1,0,1))[x,y,t]-0.025009 h[x,0] in the first argument {EvapThickFilm[0.003y,t]^2 (h^(0,1,0))[x,1y,t]^2-(0.02505 h[x,0]y,h[0t]^2 (h^(0,1,0))[x,y,t]==h[184.778t]^2)/(1+h[x,y,t])^3+<<13>>+h[x,h[xy,t]^3 ((h^(0,t]==h[x4,184.7780))[x,t]y,h[xt]+(h^(2,y2,0]==BSplineFunction[{{0.))[x,1.}y,{0.t])+3 h[x,1.}}y,<>]}. > ReplaceAll::reps:t]^2 {EvapThickFilm[0.003(h^(1,0,0))[x,y,t] ((h^(1,2,0))[x,1y,t]+(h^(3,0.025,0]0))[x,h[0y,t])+h[x,y,t]==h[184.778t]^3 ((h^(2,2,0))[x,y,t]t]+(h^(4,h[x0,0))[x,t]==h[xy,184t])==0,h[0,y,t]==h[184.778,y,t],h[<<1>>]==<<1>>,h[x,y,0]==BSplineFunction[{{0.,1.},{0.,1.}},<>]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >> NDSolve::deqn: Equation or list of equations expected instead of EvapThickFilm[0.003,0,1,0,1,0.025,0] in the first argument {EvapThickFilm[0.003,0,1,0,1,0.025,0],h[0,y,t]==h[184.778,y,t],h[x,0,t]==h[x,184.778,t],h[x,y,0]==BSplineFunction[{{0.,1.},{0.,1.}},<>]}. > ReplaceAll::reps: {EvapThickFilm[0.003,0,1,0,1,0.025,0],h[0,y,t]==h[184.778,y,t],h[x,0,t]==h[x,184.778,t],h[x,y,0]==BSplineFunction[{{0.,1.},{0.,1.}},<>]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >> NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.. >> ReplaceAll::reps: {(h^(0,0,1))[x,y,t]-0.009 h[x,y,t]^2 (h^(0,1,0))[x,y,t]^2-(0.05 h[x,y,t]^2 (h^(0,1,0))[x,y,t]^2)/(1+h[x,y,t])^3+<<13>>+h[x,y,t]^3 ((h^(0,4,0))[x,y,t]+(h^(2,2,0))[x,y,t])+3 h[x,y,t]^2 (h^(1,0,0))[x,y,t] ((h^(1,2,0))[x,y,t]+(h^(3,0,0))[x,y,t])+h[x,y,t]^3 ((h^(2,2,0))[x,y,t]+(h^(4,0,0))[x,y,t])==0,h[0,y,t]==h[184.778,y,t],h[<<1>>]==<<1>>,h[x,y,0]==BSplineFunction[{{0.,1.},{0.,1.}},<>]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >> 2 example provided ## Working example: $HistoryLength = 0;
Needs["VectorAnalysis"]
Needs["DifferentialEquationsInterpolatingFunctionAnatomy"];
Clear[Eq0, EvapThickFilm, h, Bo, \[Epsilon], K1, \[Delta], Bi, m, r]
Eq0[h_, {Bo_, \[Epsilon]_, K1_, \[Delta]_, Bi_, m_, r_}] := \!$$\*SubscriptBox[\(\[PartialD]$$, $$t$$]h\) +
m (h/(K1 + Bi h))^2 Grad[h]] + \[Epsilon]/(
Bi h + K1) + (r) D[D[(h^2/(K1 + Bi h)), x] h^3, x] == 0;
SetCoordinates[Cartesian[x, y, z]];
EvapThickFilm[Bo_, \[Epsilon]_, K1_, \[Delta]_, Bi_, m_, r_] :=
Eq0[h[x, y, t], {Bo, \[Epsilon], K1, \[Delta], Bi, m, r}];
EvapThickFilm[Bo, \[Epsilon], K1, \[Delta], Bi, m, r]];

L = 2*92.389; TMax = 3100*100;
Off[NDSolve::mxsst];
Clear[Kvar];
Kvar[t_] :=  Piecewise[{{1, t <= 1}, {2, t > 1}}]
(*Ktemp = Array[0.001+0.001#^2&,13]*)
hSol = h /. NDSolve[{
(*Bo,\[Epsilon],K1,\[Delta],Bi,m,r*)

EvapThickFilm[0.003, 0, 1, 0, 1, 0.025, 0],
h[0, y, t] == h[L, y, t],
h[x, 0, t] == h[x, L, t],
(*h[x,y,0] == 1.1+Cos[x] Sin[2y] *)

h[x, y, 0] == BSplineFunction[RandomReal[1, {30, 30, 1}]]
},
h,
{x, 0, L},
{y, 0, L},
{t, 0, TMax},
Method -> {"BDF", "MaxDifferenceOrder" -> 1},
MaxStepFraction -> 1/50
][[1]]


With the BSpline as suggested by Vitaliy Kaurov in the answer below, I have the following error:

NDSolve::deqn: Equation or list of equations expected instead of EvapThickFilm[0.003,0,1,0,1,0.025,0] in the first argument {EvapThickFilm[0.003,0,1,0,1,0.025,0],h[0,y,t]==h[184.778,y,t],h[x,0,t]==h[x,184.778,t],h[x,y,0]==BSplineFunction[{{0.,1.},{0.,1.}},<>]}.

>

ReplaceAll::reps: {EvapThickFilm[0.003,0,1,0,1,0.025,0],h[0,y,t]==h[184.778,y,t],h[x,0,t]==h[x,184.778,t],h[x,y,0]==BSplineFunction[{{0.,1.},{0.,1.}},<>]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>

## Working example:

\$HistoryLength = 0;
Needs["VectorAnalysis"]
Needs["DifferentialEquationsInterpolatingFunctionAnatomy"];
Clear[Eq0, EvapThickFilm, h, Bo, \[Epsilon], K1, \[Delta], Bi, m, r]
Eq0[h_, {Bo_, \[Epsilon]_, K1_, \[Delta]_, Bi_, m_, r_}] := \!$$\*SubscriptBox[\(\[PartialD]$$, $$t$$]h\) +
m (h/(K1 + Bi h))^2 Grad[h]] + \[Epsilon]/(
Bi h + K1) + (r) D[D[(h^2/(K1 + Bi h)), x] h^3, x] == 0;
SetCoordinates[Cartesian[x, y, z]];
EvapThickFilm[Bo_, \[Epsilon]_, K1_, \[Delta]_, Bi_, m_, r_] :=
Eq0[h[x, y, t], {Bo, \[Epsilon], K1, \[Delta], Bi, m, r}];
EvapThickFilm[Bo, \[Epsilon], K1, \[Delta], Bi, m, r]];

L = 2*92.389; TMax = 3100*100;
Off[NDSolve::mxsst];
Clear[Kvar];
Kvar[t_] :=  Piecewise[{{1, t <= 1}, {2, t > 1}}]
(*Ktemp = Array[0.001+0.001#^2&,13]*)
hSol = h /. NDSolve[{
(*Bo,\[Epsilon],K1,\[Delta],Bi,m,r*)

EvapThickFilm[0.003, 0, 1, 0, 1, 0.025, 0],
h[0, y, t] == h[L, y, t],
h[x, 0, t] == h[x, L, t],
(*h[x,y,0] == 1.1+Cos[x] Sin[2y] *)

h[x, y, 0] == BSplineFunction[RandomReal[1, {30, 30, 1}]]
},
h,
{x, 0, L},
{y, 0, L},
{t, 0, TMax},
Method -> {"BDF", "MaxDifferenceOrder" -> 1},
MaxStepFraction -> 1/50
][[1]]
`

With the BSpline as suggested by Vitaliy Kaurov in the answer below, I have the following error:

NDSolve::deqn: Equation or list of equations expected instead of EvapThickFilm[0.003,0,1,0,1,0.025,0] in the first argument {EvapThickFilm[0.003,0,1,0,1,0.025,0],h[0,y,t]==h[184.778,y,t],h[x,0,t]==h[x,184.778,t],h[x,y,0]==BSplineFunction[{{0.,1.},{0.,1.}},<>]}.

>

ReplaceAll::reps: {EvapThickFilm[0.003,0,1,0,1,0.025,0],h[0,y,t]==h[184.778,y,t],h[x,0,t]==h[x,184.778,t],h[x,y,0]==BSplineFunction[{{0.,1.},{0.,1.}},<>]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>

1