# Geometric mean with logarithmically spaced data?

조회 수: 6 (최근 30일)
L'O.G. . 2022년 7월 12일
편집: Stephen23 . 2022년 7월 12일
This is partly a Matlab question, partly conceptual. I generated three vectors with logarithmically spaced numbers using logspace. If I want to average the first element in the three vectors, then separately the second element, and so on, should I take the arithmetic or geometric mean? If the latter, how do I do this?
##### 댓글 수: 1표시 없음숨기기 없음
Stephen23 2022년 7월 12일
편집: Stephen23 님. 2022년 7월 12일
"If I want to average the first element in the three vectors, then separately the second element, and so on, should I take the arithmetic or geometric mean?"
You gave no information in your question that helps us to understand what you need those means to achieve or how you will use them. In the absence of an such information, are you looking to understand different types of mean?:

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

### 채택된 답변

DGM 2022년 7월 12일
편집: DGM 님. 2022년 7월 12일
"how do I do this?"
% three vectors:
A = logspace(0,2,10);
B = logspace(0,1.9,10);
C = logspace(0.2,2,10);
% put them in an array
allvecs = [A; B; C]
allvecs = 3×10
1.0000 1.6681 2.7826 4.6416 7.7426 12.9155 21.5443 35.9381 59.9484 100.0000 1.0000 1.6260 2.6438 4.2987 6.9895 11.3646 18.4785 30.0454 48.8527 79.4328 1.5849 2.5119 3.9811 6.3096 10.0000 15.8489 25.1189 39.8107 63.0957 100.0000
% take the arithmetic mean
avg = mean(allvecs,1)
avg = 1×10
1.1950 1.9353 3.1358 5.0833 8.2440 13.3764 21.7139 35.2647 57.2990 93.1443
% take the geometric mean
gmn = geomean(allvecs,1)
gmn = 1×10
1.1659 1.8957 3.0824 5.0119 8.1491 13.2502 21.5443 35.0303 56.9581 92.6119
##### 댓글 수: 1표시 없음숨기기 없음
John D'Errico 2022년 7월 12일
편집: John D'Errico 님. 2022년 7월 12일
I'm confused as to the question. Is it asking if you should use a geometric mean or an arithmetic mean? Surely that is your choice? @DGM tells you how to compute either, but there is no truly correct way to do something that only you know why you are doing it.
Another simple way to form a set of several geometric sequences is::
S = 2.^([0;0;0] + [1;2;3].*linspace(0,1,10))
S = 3×10
1.0000 1.0801 1.1665 1.2599 1.3608 1.4697 1.5874 1.7145 1.8517 2.0000 1.0000 1.1665 1.3608 1.5874 1.8517 2.1601 2.5198 2.9395 3.4290 4.0000 1.0000 1.2599 1.5874 2.0000 2.5198 3.1748 4.0000 5.0397 6.3496 8.0000
I'll let you figure out how I generated them..
Now, since I carefully chose the rate constants, a property of the geometric mean is that it will return the middle sequence.
geomean(S,1)
ans = 1×10
1.0000 1.1665 1.3608 1.5874 1.8517 2.1601 2.5198 2.9395 3.4290 4.0000
Do you see that the geometric mean here just reproduced the middle one?

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

### 카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

R2021b

### Community Treasure Hunt

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

Start Hunting!