i'm currently trying to remake my old function which takes a fixed value x:
function [res] = Eph(x,approximation,dot)
a = [ 0.1818 0.5099 0.2802 0.02817];
b = [ 3.2 0.9423 0.4029 0.2016];
if dot ~= 1
res = sum(a.*exp(-b.*x));
Now I'm trying to pass a vector x (so the same procedure for each x_{i}) and I want to get back as a result also a vector res
. Can someone give me a hint how to do it NOT using loops?
I think what you want can be done with a combination of matrix multiplication (for the
b.*x
part) andbsxfun
(for thea.*exp(...)
) part:Example with your code, scalar
x
:Example with my code, vector
x
: