MATLAB: Error Plotting a Multi-variable Function with Respect to a Single Variable.

functionmatlab functionmatrixmatrix dimensionsmatrix dimentions do not agreemultivariable

I have created the following five functions (the fourth contains two internal functions):
function M = actomic_form_factor(N_i, L_i, M_i, N_f, L_f, M_f, lambda, scattering_angle)
k = 2.*pi/lambda;
f = @(r, theta, phi) wave_function_product(N_i, L_i, M_i, N_f, L_f, M_f, r, theta, phi).* plane_wave_factor(k, k, theta, phi, scattering_angle, r);
M = integral3(f,0,Inf,0,pi,0,2*pi,'AbsTol',1e-5,'RelTol',1e-5);
end
function t = plane_wave_factor(k_i, k_f, theta, phi, scattering_angle, r)
t = exp(1i.*dot(k_i, k_f, theta, phi, scattering_angle, r));
end
function p = wave_function_product(n_i, l_i, m_i, n_f, l_f, m_f, r, theta, phi)
p = hydrogenic_wave_function(n_i, l_i, m_i, r, theta, phi).* ...
conj(hydrogenic_wave_function(n_f, l_f, m_f, r, theta, phi));
end
function psi = hydrogenic_wave_function(n, l, m, r, theta, phi)
a = 1; % Bohr radius in m
% angular part (Condon-Shortley)
SphericalYlm = @(l, m, theta, phi) (-1)^m * sqrt((2 * l + 1) / (4 * pi) * ...
factorial(l - abs(m)) / factorial(l + abs(m))) * ...
AssociatedLegendre(l, m, cos(theta)) .* exp(1i * m * phi);
% radial part
R = @(n, l, r) sqrt((2 / (a * n))^3 * factorial(n - l - 1) / (2 * n * factorial(n + l))) .* ...
exp(-r / (a * n)) .* (2 * r / (a * n)).^l * 1 / factorial(n - l - 1 + 2 * l + 1) .* ...
AssociatedLaguerre(n - l - 1, 2 * l + 1, 2 * r / (a * n));
% wave function
psi = R(n, l, r) .* SphericalYlm(l, m, theta, phi);
% functions
function Anm = AssociatedLaguerre(n,m,x)
Anm = 0;
for i = 0 : n
Anm = Anm + factorial(m + n) * nchoosek(m + n, n - i) / factorial(i) * (-x).^i;
end
end
function Alm = AssociatedLegendre(l,m,x)
Alm = 0;
for h = 0 : floor(1/2 * l - 1/2 * abs(m))
Alm = Alm + (-1)^h * nchoosek(l - 2 * h, abs(m)) * nchoosek(l, h) * ...
nchoosek(2 * l - 2 * h, l) * x.^(l - 2 * h - abs(m));
end
Alm = (1 - x.^2).^(abs(m) / 2) .* (factorial(abs(m)) / 2^l * Alm);
end
end
function dot = dot(k_i, k_f, theta, phi, scattering_angle, r)
a = k_f.*r.*sin(scattering_angle).*sin(theta).*sin(phi);
b = (k_i - k_f.*cos(scattering_angle)).*r.*cos(theta);
dot = -(a + b);
end
I need to plot atomic_form_factor(N_i, L_i, M_i, N_f, L_f, M_f, lambda, scattering_angle) with respect to scattering angle (y axis = atomic_form_factor, x axis = scattering_angle) while holding the other inputs at specific constant values. I have tried inputing the follwing code into the command line:
x = 0:2*pi/100:2*pi;
y = atomic_form_factor(1, 0, 0, 1, 0, 0, 10000, x);
plot(x,y)
I recieve the error:
Error using .*
Matrix dimensions must agree.
Error in dot (line 7)
a = k_f.*r.*sin(scattering_angle).*sin(theta).*sin(phi);
Could someone tell me how I can fix this problem? Thank you in advance.

Best Answer

x = 0:2*pi/100:2*pi;
for i=1:numel(x)
y(i) = actomic_form_factor(1, 0, 0, 1, 0, 0, 10000, x(i));
end
plot(x,y)