【问题标题】:“Expecting a constant value” error when constructing a NetLogo list构造 NetLogo 列表时出现“期望一个常数值”错误
【发布时间】:2014-06-09 23:06:31
【问题描述】:

我目前正在使用 IFS 构造 scheme 在 NetLogo 中创建征费 C 曲线的图形表示。我发现了两个函数,它们描述了如何迭代地映射两只海龟的位置,并且应该在数千次迭代后产生所需的曲线。到目前为止,这是我的代码:

 ;;;;;; some useful complex operations

 ; to take re(z) of a complex number a + bi inputed as the list of coordinates [a b]

 to-report re [z]
 report first z
 end


 ; to take im(z)

 to-report im [z]
 report last z
 end

 ; to multiply two complex numbers

 to-report complex_mul [z1 z2]
 report list (re z1 * re z2 - im z1 * im z2) 
             (re z1 * im z2 + im z1 * re z2) 
 end


 ; to add complex numbers

 to-report complex_add [z1 z2]
 report list (re z1 + re z2)
             (im z1 + im z2)
 end


 ; to dilate complex numbers by a scalar fraction

 to-report complex/real [z1 real]
 report list (re z1 / real)
             (im z1 / real)
 end 

 ; to initialize

 to setup
 ca
 setup-turtles
 reset-ticks
 end


 ; create 2 turtles located at the initial set of points {0, 1}

 to setup-turtles
 crt 2
 ask turtle 0 [ setxy 0 0]
 ask turtle 1 [ setxy 1 0]
 ask turtles [ pd]
 end


 ; to create the first function to transform the turtle's location

 to-report nextz_1 [z] 
 report complex/real (complex_mul [1 -1] z) 2
 end 


 ; to create the second function to transform the turtle's location

 to-report nextz_2 [z]
 report complex_add [1 0] 
                    (complex/real (complex_mul [1 1] 
                                                (complex_add z [-1 0]))
                                   2) 
 end

 ; finally we are creating the Levy Curve

 to levy
  ask turtles [ run one-of (list task setxy re (nextz_1 [xcor ycor]) im (nextz_1 [xcor ycor])
                                 task setxy re (nextz_2 [xcor ycor]) im (nextz_2 [xcor ycor])
                               )
           ]

 end

但是,我在调用 re (nextz_1 [xcor ycor]) 等的“征税”代码块中收到一条错误消息,说 NetLogo 期望一个常数值代替 xcor 和 ycor。

我该如何解决这个问题?

【问题讨论】:

    标签: netlogo fractals


    【解决方案1】:

    http://ccl.northwestern.edu/netlogo/docs/faq.html#listexpectedconstant,NetLogo 常见问题解答说:

    如果列表只包含常量,您只需在其周围加上方括号即可将其写下来,例如[1 2 3]

    如果您希望列表包含在运行时可能会发生变化的项目,则不能直接写下该列表。相反,您使用 list 原语构建它。

    您实际上在代码中的其他一些地方得到了这一点,但是在levy 过程中,您需要替换例如[xcor ycor]list xcor ycor

    对于 NetLogo,[xcor ycor] 看起来像一个记者块,而不是一个列表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多