如何计算标题的加权平均值?

How do I figure the weighted mean of headings?

Get mean heading of neighboring turtles

to-report mean-heading [ headings ]
  let mean-x mean map sin headings
  let mean-y mean map cos headings
  report atan mean-x mean-y
end   

从那个答案中我得到了一部分,但我希望每个标题都根据海龟的大小加权。

类似于

 sum [heading * size] of turtles / sum [size] of turtles

但是,你知道,这确实有效。

如果您接受 turtleset 而不是标题列表,则:

to-report weighted-mean-heading [turts]
  let mean-x mean [size * sin heading] of turts
  let mean-y mean [size * cos heading] of turts
  report atan mean-x mean-y
end