11 個のキーワードで学ぶ統計学入門 1 / 相加平均 (算術平均)

参考: 日経ソフトウエア 2018年 1 月号, pp.76-87
 

  • Calculator の場合:

構文: mean(リスト)
実行結果:
f:id:ti-nspire:20180507203132p:plain:w300
 

  • Nspired Lua で Nspire ネイティブの組込函数を実行する場合 1:
seq2 = {1,2,3,4,5,6,7,8,9,10}

function mean(list)
   var.store("list", list) -- あらかじめ Nspire ネイティブ側の変数に値を代入しておく。
   return math.eval("mean(list)")
end
function on.resize(gc)
   print(mean(seq2))
end

実行結果:
f:id:ti-nspire:20180508060122p:plain:w300
 

  • Nspired Lua で Nspire ネイティブの組込函数を実行する場合 2 (この方法だと Nspire ネイティブ側の変数が汚れない):
seq2 = {1,2,3,4,5,6,7,8,9,10}

function mean(list)
   local temp = "{"..table.concat(list, ",").."}"
   --return math.eval("mean("..temp..")")
   return math.eval(string.format("mean(%s)", temp))
end
function on.resize()
   print(mean(seq2))
end

 

  • Lua だけで組む場合:
function sum(list)
   local temp = 0
   for i = 1, #list do
      temp = temp + list[i]
   end
   return temp
end
function mean(list)
   return sum(list) / #list
end

seq3 = {1,2,3,4,5,6,7,8,9,10}
print(mean(seq3))

実行結果:

―――――――――――――――――――――――――――
Wolfram の場合:
構文: Mean[リスト]
実行結果:
f:id:ti-nspire:20180507210114p:plain:w300
―――――――――――――――――――――――――――
Excel の場合:
構文: AVERAGE(始点セル:終点セル)
f:id:ti-nspire:20180508095032p:plain:w300