There are some time when I use anonymous functions which include product of other anonymous functions. For example, as two anonymous functions
h_exp2 = @(x)exp(1i.*sqrt(x.^2+A^2));
and their product
h_prod = @(x)(h_exp1(x) .* h_exp2(x));
This expression is inefficient in that the product h_prod call exp function twice and it is slower than
h_prod2 = @(x)exp(1i.*(x+sqrt(x.^2+A^2)));
which call exp function once. There are cases where this consumption of time become dominant if h_prod is called millions of times or more.
Of course, its enough to use h_prod2 where the respective constituents are simple, but it seems to become less readable and less extendable when the formulation is basically not simple.
Are there any methods to cope with this? Please forgive my inexperience of program development.