0

我会在 Netlogo 中创建一个基于刻度和价格变量的周期性函数。

我想要一个价格保持在 2 范围(0 和 1)之间的功能,如果我可以选择周期性,我会很棒。

我的可重复的小例子:

patches-own[
 price 
]

to setup
  clear-all
  ask patches [
   set price 0.1 
  ]
  reset-ticks
end

to go
  ask patches [
    set price (sin ticks) + price
  ]
  tick

end

先感谢您

4

1 回答 1

1

听起来您只想要一个mod基于循环的循环。

to test
  ca
  reset-ticks
  print map price n-values 100 [?]
  print map [price02 0 1 ?] n-values 100 [?]
end

to-report price [#ticks]
  let _cycle 10  ;cycle length
  let _first 3   ;length of first cycle component
  report ifelse-value (#ticks mod _cycle < _first) [
    0.1
  ][
    0.2
  ]
end

编辑:

或者,您可能只是尝试缩放正弦波。

to-report price02 [#min #max #ticks]
  let _cycle 10
  let _sin sin (#ticks * 360 / _cycle)
  let _scaledsin (1 + _sin) / 2
  report #min + (#max - #min) * _scaledsin
end
于 2016-07-29T16:34:00.310 回答