How make a list of cumulative sum in netlogo

前端 未结 4 1002
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-07 06:43

How can i make a list of cumulative sum of a other list?

i tried it that way:

;;all temperatrue-values around the turtle saved in list 
set tempera         


        
4条回答
  •  佛祖请我去吃肉
    2021-01-07 07:22

    your code for a cumulative sum works (except that I think you need lput rather than fput. You can see it with this:

    to test
      let ll [1 2 3 4] 
      let tempsum 0 
      let tempsum_list [] 
      foreach ll 
      [ set tempsum (tempsum + ? ) 
        set tempsum_list lput tempsum tempsum_list 
      ]
      print tempsum_list
    end
    

    Did the error highlight the line set temperature_values (list [(output-heat + 1)^ Freedom] of neighbors)? Try putting a space after between ) and ^. NetLogo is picky about space around mathematical operators.

提交回复
热议问题