2016-07-29 90 views
0

我會在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 

預先感謝您

回答

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 
+0

不是真的,我希望所有變量介於0和1之間......類似verhulst或trigo函數 – delaye

+0

請參閱上面的編輯。 – Alan

+0

非常感謝你! – delaye