MATLAB: Is there a difference between applying Laplacian operator vs. divergence to gradient of the data

laplaciantMATLAB

Laplacian operator will be equvalient to applying Divergence to the Gradient of the data. However, using the DEL2, DIVERGENCE, GRADIENT function in MATLAB, the results are different between the two methods. For example,
[x, y] = meshgrid(-1:.1:1);
A = sqrt(x.^2 + y.^2);
% the laplacian
Laplacian_1 = del2(A);
% second method to calculate the laplacian
[dx, dy] = gradient(A);
Laplacian_2 = divergence(dx, dy);
Laplacian_sq_error = (Laplacian_1 - Laplacian_2).^2;
The error is in the order of 1e-2.

Best Answer

MATLAB provides finite difference approximations to the partial differential operators gradient, divergence and Laplacian. With a spacing of size h in
[x,y] = meshgrid(-1:h:1)
the finite difference approximations have accuracy proportional to h^2.
Related Question