'Dot indexing is not supported for variables of this type [closed]

I can't make this code to work. Can someone please tell me why? I have indicated which line the error comes up at (Ar).

% Define the grid
step = 0.1;
min = -1; max = 1;
[x, y] = meshgrid(min:step:max, min:step:max);
% Coordinate transformation
r = sqrt(x.^2 +y.^2); phi = atan2d(y, x);
% Given vector
Ar = r.exp(-r.^2/9)  --> (" Dot indexing is not supported for variables of this type")
Ax = Ar.*cosd(phi)
Ay = Ar.*sind(phi)

% Calculate divergence
D = divergence(x, y, Ax, Ay);
% Create a figure
quiver(x, y, Ax, Ay)
grid on; axis square; hold on contour(x, y, D, 30)
xlabel('x'); ylabel('y')
xlim([min max]); ylim([min max]); set(gca, 'Fontsize', 18)
% Choose divergence test points
probe_ind = [16, 16];
probe_x = x(probe_ind(1), probe_ind(2)); probe_y = y(probe_ind(1), probe_ind(2)); probe_r = sqrt(probe_x^2 + probe_y^2);
% Divergence calculated in MATLAB
probe_div = D(probe_ind(1), probe_ind(2));
% Divergence expression calculated manually
calcul_div = 1.78
% Print the answers
fprintf('x = %.10f y = %.10f\n', probe_x, probe_y); fprintf('divergence calculated analytically = %.10f\n', calcul_div); fprintf('divergence calculated by matlab = %.10f\n', probe_div);


Solution 1:[1]

What do you expect this to do? r.exp() is mostly used to access field exp of structure r, or method exp() of object r, belonging to a certain class. Given that r is just a matrix, you cannot dot-index into it. Most probable you've missed an *, i.e. r.*exp(), resulting in element-wise multiplication.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Adriaan