We wish to solve for the multiple Laplacian of a function, and here we use sum of E-exponential functions as an example:
Clear[g]
t[x_, y_, z_, i_] := Random[] Exp[I (Random[] x + Random[] y + Random[] z)]
g[x_, y_, z_] := {Sum[t[x, y, z, i], {i, 1, i0}], Sum[t[x, y, z, i], {i, 1, i0}], Sum[t[x, y, z, i], {i, 1, i0}]}
g1[x, y, z] = g[x, y, z]
Here's the questions:
- It takes a long time to compute multiple Laplacians using Nest, how to speed it up? (Functions in real-problems are more complex than E-exponential functions, and thus take more time to the point of being unacceptable.)
n0 = 200;
i0 = 10;
lap1[n_, f_] := Nest[Laplacian[#, {x, y, z}] &, f, n]
AbsoluteTiming[lap1[n0, g1[x, y, z]]][[1]]
2.By writing the Laplace in the form of second-order derivative, the computation time is sharply reduced; can the computation be speeded up further on this basis?
lap2[n_, f_] := Nest[(D[#, {x, 2}] + D[#, {y, 2}] + D[#, {z, 2}]) &, f, n]
AbsoluteTiming[lap2[n0, g1[x, y, z]]][[1]]
3.It can be noticed that the Precision of the second-order derivative and Laplacian is not the same, what is the reason?
s1 = lap1[n0, g1[x, y, z]] /. {x -> 0.3, y -> 7, z -> 0.5}
s2 = lap2[n0, g1[x, y, z]] /. {x -> 0.3, y -> 7, z -> 0.5}
s1 - s2
- Is it possible to use Compile to speed up multi-order derivative? If it is possible how to do.