"I tried the following naive code but I only obtained a scalar and not the desired matrix"
You obtained a scalar because you assigned a scalar.
And you are using non-scalar value as a condition to if-else statements, which evaluates all the values to a condition and proceeds accordingly.
if [0 1; 1 2]
disp('if')
elseif 3*ones(5)
disp('elseif')
else
disp('else')
end
elseif
It depends on the operation but this should work for a good amount of cases. If this doesn't work, please specify the 'expensive operation' you are trying to implement.
Thanks for the answer. How to do expensive operations for these indices? Suppose that for r > t the function returns some complicated function of r and t that we denote g1(r,t). We would like to calculate g1(r,t) only when we are sure that r > t.
Also, for r < t, the function returns some complicated function of r and t that we denote g2(r,t). How to specify that already in the definition of the function f so as to avoid computing both g1 and g2 for all the values of r and t? I can simply make f return g1 .* (r > t) + g2 .* (r < t) but this would mean that the function f would have to compute g1 when r < t and g2 when r > t (very expensive operations). Any help is very much appreciated. Thank you,
g1 and g2 involve infinite sums of terms involving hypergeom functions. They are really very complicated and there is no real interest in providing their expressions explicitly here I guess. If we could have a solution for general g1 and g2, that would be a dream. Thanks Dyuman.
I realized that using parfor for parallel computation leads to a quick evaluation of the kernel functions without the need for vectorizing the implementation. Sometimes simple approaches save both time and energy. Thanks for your valuable help anyway.
No se puede completar la acción debido a los cambios realizados en la página. Vuelva a cargar la página para ver el estado actualizado.
Translated by
Seleccione un país/idioma
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.