필터 지우기
필터 지우기

Taking the sum of exponentials

조회 수: 6 (최근 30일)
L'O.G.
L'O.G. 2022년 3월 22일
답변: Star Strider 2022년 3월 22일
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
Voss
Voss 2022년 3월 22일
Since a is already a column vector, the (:) is unnecessary, you're right.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2022년 3월 22일
If it matters, . And a is a vector of .’
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.

추가 답변 (1개)

Paul
Paul 2022년 3월 22일
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
ans = 3×2
1.0000 2.0000 0.5000 1.0000 0.3333 0.6667
exp(x./a(:)) % element wise exp
ans = 3×2
2.7183 7.3891 1.6487 2.7183 1.3956 1.9477
sum(exp(x./a(:))) % sum down the columns
ans = 1×2
5.7626 12.0551

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by