matlab z算子,怎样换作MATLAB算子?

function cooperation-own=(energy  c-type)

patches-own ( grass temp)

globals (num-coop num-greed)

breeds (coop-greed)

to setup

ca

ask patches (

set grass max-grass

color grass

)

crt number-coop + number-g

ask turtles (

set c-type random 2 ; set the breed

create-coop number-coop

create-greed number-g

ifelse (c-type = 0 )

(setc pink)

(setc blue)

setxy random 2000 random 2000

set energy metabolism * 4

)

set-plot-pen "coop"

set-plot-pen-color pink

set-plot-pen "greed"

set-plot-pen-color blue

set-plot-x-range 0 1

set-plot-y-range 0 1

auto-plot-on

end

to go

ask turtles (

ifelse c-type = 0

[

move

eat-coop

reproduce

]

[

move

eat-greed

reproduce

]

]

ask patches [

grow-grass

color-grass

]

set num-coop 0

set num-greed 0

ask turtles [ ifelse c-type = 0 [ set num-coop num-coop + 1][set

num-greed num-greed + 1] ]

set-plot-pen "coop"

plot num-coop

set-plot-pen "greed"

plot num-greed

end

to reproduce

if(energy > rep-level)[

set energy energy - rep-cost

hatch[]

ifelse (c-type = 0)

[

if ((random 100) < 1)

[setbreed greed]

if (breed = greed)

[ask greed [setc blue]]

ask coop [setc pink]

setc pink

]

[

if ((random 100) < 8)

[setbreed coop]

if (breed = coop)

[ask coop [setc pink]]

ask greed [setc blue]

setc blue

]

]

end

to grow-grass

set temp l-h-thresh

ifelse ( grass >= temp)[

if(h-g-chance >= (random 100))[

set grass grass + 1

]

][

if(l-g-chance >= (random 100))[

set grass grass + 1

]

]

if(grass > max-grass ) [set grass max-grass]

end

to color-grass

scale-pc green grass 0 (2 * max-grass)

end

to move

fd 1 / viscosity

seth random 360

set energy energy - metabolism

if (energy < 0) [die]

end

to eat-coop

if(grass > l-h-thresh )[

set grass grass - 1

set energy energy + grass-energy

]

end

to eat-greed

if(grass > 0)[

set grass grass - 1

set energy energy + grass-energy

]

end

@#$#@#$#@

CC-WINDOW

10

262

307

437

Default

BUTTON

67

10

119

37

go

go

T

1

T

OBSERVER

BUTTON

9

9

58

37

setup

setup

NIL

1

T

OBSERVER

SLIDER

140

60

257

97

number-coop

number-coop

0.0

100.0

6.0

1.0

1

SLIDER

7

60

116

93

number-g

number-g

0.0

100.0

6.0

1.0

1

SLIDER

139

210

270

242

l-h-thresh

l-h-thresh

0.0

99.0

5.0

1.0

1

SLIDER

139

138

270

167

h-g-chance

h-g-chance

0.0

99.0

75.0

1.0

1

SLIDER

142

18

254

52

viscosity

viscosity

1.0

20.0

12.0

1.0

1

SLIDER

139

174

270

204

max-grass

max-grass

0.0

40.0

10.0

1.0

1

SLIDER

4

209

127

241

rep-level

rep-level

0.0

200.0

101.0

1.0

1

SLIDER

5

139

129

168

grass-energy

grass-energy

0.0

200.0

51.0

1.0

1

SLIDER

6

102

130

134

metabolism

metabolism

0.0

99.0

10.0

1.0

1

SLIDER

139

101

270

133

l-g-chance

l-g-chance

0.0

99.0

30.0

1.0

1

PLOT

495

31

744

230

plot1

xAxis

yAxis

SLIDER

6

174

129

202

rep-cost

rep-cost

0.0

99.0

40.0

1.0

1

GRAPHICS-WINDOW

284

27

488

231

12

12fi([], 1, 16)

8.16

1

end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值