2012-11-28 32 views
1

ķ傢伙: 什麼是平均{1,2,3} 2吧? 顯然並非如此:GNU八度的均值函數

octave:50> B = [1, 2, 3] 
B = 

    1 2 3 

octave:51> mean(B) 
ans = 

    0.42478 
    0.55752 
    0.73451 

octave:52> B = [1;2;3] 
B = 

    1 
    2 
    3 

octave:53> mean(B) 
ans = 

    0.42478 
    0.55752 
    0.73451 

難道我只是不知道意味着什麼?

+3

我想你覆蓋'mean'? – Tim

回答

5

您可能正在使用與Octave中定義的默認值不同的mean函數。我試過你的代碼,並得到2作爲答案。爲了確定這一點,在八度提示符下輸入以下命令

which mean 

這是我的輸出

`mean' is a function from the file /usr/share/octave/3.4.3/m/statistics/base/mean.m 

如果我通過輸入以下代碼

function retval = mean (v) 
    retval = v/e; 
endfunction 

我得到一個不同的定義meanmean(B)當答案爲B = [1, 2, 3]

ans = 

    0.36788 0.73576 1.10364 

如果我輸入命令which mean我現在得到這個

`mean' is a command-line function