Taking the sum of exponentials
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
L'O.G.
am 22 Mär. 2022
Beantwortet: Star Strider
am 22 Mär. 2022
To do the calculation,
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/937934/image.png)
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
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/938124/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/937949/image.png)
x = linspace(0.01,100,10000);
f_x = sum(exp(-x./a(:)));
1 Kommentar
Akzeptierte Antwort
Star Strider
am 22 Mär. 2022
‘If it matters,
. And a is a vector of
.’
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/937999/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/938004/image.png)
I don’t see ‘t’ defined anywhere, so it depends on what relationship ‘t’ has to ‘x’ or a.
However, since as @_ noted, since a is already a column vector by definition, the (:) is not necessary. The important aspect is that with respect to MATLAB coding, ‘x./a’ must be a matrix in order that sum produces the row vector necessary for the result.
0 Kommentare
Weitere Antworten (1)
Paul
am 22 Mär. 2022
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!