Taking the sum of exponentials
Show older comments
To do the calculation,

is the following code correct? Is the (:) necessary? I think that makes a column vector, but I don't think it's necessary. I don't think cumsum would be useful here. Could somebody please advise? If it matters,
. And a is a vector of
.
x = linspace(0.01,100,10000);
f_x = sum(exp(-x./a(:)));
1 Comment
Voss
on 22 Mar 2022
Since a is already a column vector, the (:) is unnecessary, you're right.
Accepted Answer
More Answers (1)
Break it up with simple inputs to see what's going on:
x = [1 2]; % row vector
a = [1 2 3]; % row vector
x./a(:) % implicit expansion makes a 3 x 2 matrix
exp(x./a(:)) % element wise exp
sum(exp(x./a(:))) % sum down the columns
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!