0

I would create a periodic function in Netlogo based on ticks and a price variable.

I would like a function where price is maintained between 2 rang (0 and 1) and I will be great if I can choose the periodicity.

my small reproducible example :

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

Thank you in advance

delaye
  • 1,357
  • 27
  • 45

1 Answers1

1

It sounds like you just want a mod based cycle.

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

Edit:

Alternatively, you may simply be trying to scale a sine wave.

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
Alan
  • 9,410
  • 15
  • 20
  • not really, I want all variable between 0 and 1 ... something like a verhulst or trigo function – delaye Jul 29 '16 at 17:00