"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.
Impossible de terminer l’action en raison de modifications de la page. Rechargez la page pour voir sa mise à jour.
Translated by
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.