I have a function with the following for-loop that seems to be pretty efficient. However, I'm wondering if this is the most efficient implementation, or is there a faster way to do this computation. There is a helper function too "Pnm_index" that finds the proper index to store the computations in the final output variable Pnms. I've included that function as well below. Since this helper function is so simple I'm also wondering if eliminating it will provide any speed up. Any insight is appreciated!
tic
s = sin(3*pi/7);
c = cos(3*pi/7);
p = 5; % input variable
Pnms = zeros(1,((p+1)*(p+2))*(2^-1)); % preallocate the output
Pn0 = 1.0; % initialize
fact = 1.0; % initialize
for m = 0:p
Pnm = Pn0;
i = Pnm_index(m, m); % find the proper index, see function below
Pnms(i) = Pnm; % store the output
tmp1 = Pnm;
Pnm = c * (2 * m + 1) * tmp1;
for n = m+1:p
i = Pnm_index(n, m); % find the proper index, see function below
Pnms(i) = Pnm; % store the output
tmp2 = tmp1;
tmp1 = Pnm;
Pnm = (c * (2 * n + 1) * tmp1 - (n + m) * tmp2) / (n - m + 1);
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.