Netlogo创建周期性函数

问题描述:

我会在Netlogo中创建一个基于滴答和价格变量的周期性函数。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 

预先感谢您

这听起来像你只是想要一个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 
+0

不是真的,我希望所有变量介于0和1之间......类似verhulst或trigo函数 – delaye

+0

请参阅上面的编辑。 – Alan

+0

非常感谢你! – delaye