# How to make this moving surface a continuous and derivable function?

I'm having troubles in defining a function of three variables: $$t$$, $$x$$, $$y$$, from a moving bumpy surface that should be derivable relative to its three variables. Here's the animated surface code, which works very well in the Manipulate box:

Clear["Global*"]

size = 30;
Z0[x_, y_] := RandomReal[{-1, 1}]
amplitude[x_, y_] := RandomReal[{0.5, 1.5}]
frequency[x_, y_] := RandomReal[{0.25, 0.75}]
phase[x_, y_] := RandomReal[{0, 2Pi}]

(*Collection of random oscillators: *)

oscillators[t_] = Table[{x, y, Z0[x, y] + amplitude[x, y]Sin[frequency[x, y]t + phase[x, y]]}, {x, -size, size, 4}, {y, -size, size, 4}];

(* A bumpy surface fleshing the random oscillators: *)

bumpy[t_, x_, y_] := Interpolation[Flatten[oscillators[t], 1], Method -> "Spline"][x, y]

derivativeT[t_, x_, y_] := D[bumpy[t, x, y], t] (* Doesn't work!*)
derivativeX[t_, x_, y_] := D[bumpy[t, x, y], x] (* Works well! *)
derivativeY[t_, x_, y_] := D[bumpy[t, x, y], y] (* Works well! *)

Manipulate[
Plot3D[
Evaluate[bumpy[t, x, y]],
{x, -10, 10}, {y, -10, 10},
PlotPoints -> ControlActive[20, 60],
PlotRange -> {{-10, 10}, {-10, 10}, {-3, 3}},
Axes -> True,
AxesOrigin -> {0, 0},
AxesStyle -> Directive[GrayLevel[0.5]],
ColorFunction -> "Rainbow",
MeshFunctions -> {(#3&)},
MeshStyle -> GrayLevel[0.25],
ImageSize -> 500
],
{t, 0, 40, 0.01,
ImageSize -> Large,
Appearance -> {"Labeled", "Closed"},
AppearanceElements -> {"InputField", "Slider"}
},
ControlPlacement -> Bottom,
FrameMargins -> None,
FrameLabel -> {None, None,
Style["Some Title Here!", Bold, 14, FontFamily -> "Helvetica"]}
]


Preview of what this code is doing (the animation is very smooth and pretty cool!): How can I turn bumpy[t_, x_, y_] into a function that could be derivable relative to its time $$t$$ parameter, and be plotted?

I'm able to plot the derivatives relative to the two other variables, $$x$$ and $$y$$:

derivativeX[t_, x_, y_] := D[bumpy[t, x, y], x]
derivativeY[t_, x_, y_] := D[bumpy[t, x, y], y]


But currently the following doesn't work:

derivativeT[t_, x_, y_] := D[bumpy[t, x, y], t]


In this case, I get the following error message:

General::ivar : 0 is not a valid variable.

Note: The solution should work with Mathematica 7, since I'm currently stuck with this version for some time, because of an old computer...

This question appears to be similar to this one (without any answers): How to derive a 3D interpolated surface?

EDIT: Here's a simple ListPointPlot3D to show the oscillators that define the "bones" of the bumpy surface:

Manipulate[
ListPointPlot3D[
Flatten[oscillators[t], 1],
PlotRange -> {{-10, 10}, {-10, 10}, {-3, 3}},
Axes -> True,
AxesOrigin -> {0, 0},
AxesStyle -> Directive[GrayLevel[0.5]],
AxesLabel -> {Style["X",  Bold, 14],Style["Y",  Bold, 14]},
ImageSize -> 700
],
{t, 0, 40, 0.1,
ImageSize -> Large,
Appearance -> {"Labeled", "Closed"},
AppearanceElements -> {"InputField", "Slider"}
},
ControlPlacement -> Bottom,
FrameMargins -> None,
FrameLabel -> {None, None,
Style["Filed of random oscillators", Bold, 14,
FontFamily -> "Helvetica"]}
]

• rB[t_, x_, y_] := Interpolation[Flatten[randomPoints[t], 1], Method -> "Spline"][x, y]?
– kglr
Dec 14, 2020 at 21:24
• @kglr, this is what I tried, but I'm getting a warning message from Mathematica: Interpolation::maple: The Spline method could not be used because the data could not be coerced to machine real numbers. And the output is then all wrong...
– Cham
Dec 14, 2020 at 21:27
• It works in version 11.3.0 (windows 10 64b) and version 12.2.0 (wolfram cloud) with no warning message and the picture looks same as the picture from Evaluate[randomBumps[t][x, y]].
– kglr
Dec 14, 2020 at 21:46
• I can confirm using kglrs code in v12 on OSX, it runs smoothly.... and can be plotted...not to say you need to upgrade...but version 12 does have nice features you might want to take advantage of since verison 7.... Dec 14, 2020 at 22:30
• Maybe try it on the free version of the Wolfram Cloud? That uses version 12. Dec 15, 2020 at 16:30

We need some small modification of the code to plot derivatives

size = 30;
Z0[x_, y_] := RandomReal[{-1, 1}];
amplitude[x_, y_] := RandomReal[{0.5, 1.5}];
frequency[x_, y_] := RandomReal[{0.25, 0.75}];
phase[x_, y_] := RandomReal[{0, 2 Pi}];
randomPoints[t_] :=
Table[{x, y,
Z0[x, y] +
amplitude[x, y] Sin[frequency[x, y] t + phase[x, y]]}, {x, -size,
size, 4}, {y, -size, size, 4}];
randomPoints1[t_] :=
Table[{x, y,
Z0[x, y] +
amplitude[x, y] frequency[x, y] Cos[
frequency[x, y] t + phase[x, y]]}, {x, -size, size,
4}, {y, -size, size, 4}];

randomBumps[t_] :=
Interpolation[Flatten[randomPoints[t], 1], Method -> "Spline"]
randomBumps1[t_] :=
Interpolation[Flatten[randomPoints1[t], 1], Method -> "Spline"];


Now we can define derivatives as follows

derivativeT[t_, x_, z_] := randomBumps1[t][x, z];
derivativeX[t_, x_, z_] := D[randomBumps[t][x, z], x];
derivativeY[t_, x_, z_] := D[randomBumps[t][x, z], z];


Visualization of derivativeT[]

Manipulate[
Plot3D[Evaluate[
derivativeT[t, x,
y]],{x, -10, 10}, {y, -10, 10},
PlotPoints -> ControlActive[20, 60],
PlotRange -> {{-10, 10}, {-10, 10}, {-3, 3}}, Axes -> True,
AxesOrigin -> {0, 0}, AxesStyle -> Directive[GrayLevel[0.5]],
ColorFunction -> "Rainbow", MeshFunctions -> {(#3 &)},
MeshStyle -> GrayLevel[0.25], ImageSize -> 700], {t, 0, 40, 0.01,
ImageSize -> Large, Appearance -> {"Labeled", "Closed"},
AppearanceElements -> {"InputField", "Slider"}},
ControlPlacement -> Bottom, FrameMargins -> None,
FrameLabel -> {None, None,
Style["Some Title Here!", Bold, 14, FontFamily -> "Helvetica"]}]
` • randomPoints[t_] := and randomPoints1[t_] := shouldn't have a :=. The motion is continuous in Manipulate only with =, instead of :=.
– Cham
Dec 15, 2020 at 0:09
• It appears to work, but at the price of telling explicitly the time derivative. I'll have to study this solution, to see if it works as initial conditions in my code. I suspect that it will complicate my full code...
– Cham
Dec 15, 2020 at 0:14
• Oh, and in randomPoints1, there shouldn't be Z0[x, y], since it's supposed to be the time derivative of randomPoints.
– Cham
Dec 15, 2020 at 0:19
• @Cham I don't understand you remarks, since I only seen your code and try to make it working with version 7. Actually the code did smooth picture for derivatives. But it looks like it is not what do you expect? Dec 15, 2020 at 0:35
• The problem with your solution is that it defines another function. Please, see the new formulation of the question. I need an unique function bumpy[t, x, y] to get all three derivatives (relative to variables $t$, $x$, $y$)
– Cham
Dec 16, 2020 at 23:35