0
$\begingroup$

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:

  1. 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
  1. Is it possible to use Compile to speed up multi-order derivative? If it is possible how to do.
$\endgroup$
0

2 Answers 2

1
$\begingroup$

At 3.) You mix up the notions of (absolute) accuracy and (relative) precision. The relative error is computed by Abs[s1 - s2]/Abs[s1] and it s{1.94629*10^-15, 1.09421*10^-14, 1.82465*10^-15}. So we have roughly 14 digits of precision here. That's basically as good as double precision floating point number can get.

At 4.) No, Compile cannot handle symbolic manipulations.

$\endgroup$
1
$\begingroup$

Consider the simple polynomial expansion of higher derivatives like powers of squares

Function@@{f,((ExpandAll[(x^2+y^2+z^2)^200]  /.
  { Plus->Inactive[Plus],Times->List,x_Symbol^n_:>{x,n}})/.
    {{x_Symbol,n_Integer}:> Inactive[D][f,{x,n}],
     {n_Integer,{ a_,m_Integer},b___List}:> n Inactive[D][f,a,b]})/.
  {Inactive[Plus][a___,b_Symbol,c___]:>Inactive[Plus][a,Inactive[D][f,b] ,c]}}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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