In my netlogo program I have a ratio that fluctuates over time.
In the program time is set to weeks. There are 5200 weeks in each simulation.
If the ratio falls below 0.70 I would like to set a parameter R0 to zero for 520 weeks then go back to the baseline of 0.03.
Right now I have
ifelse ( ratio < T ) [ set R0 0 ] [set R0 0.03]
where T is set to 0.70, however, how do I set R0 to 0 for ten years and then back to 0.03?
Thank you,
With the code you have RO is always set to 0 or 0.03.
Assuming each tick is a month use a variable called timer
if timer > 0 [set timer timer - 1 if timer = 0 [set ratio 0.03]]
if (ratio < T)[set ratio 0 set timer 120]
it works as well for a patch, a turtle or a global
Related
I try to figure out, how to create an output that has an equal distribution on the random sample. Based on the code snippet below, the function creates three random numbers for three items in a list. This values gets than compared to each other, and the maximal value of them, gets count. However I am trying to figuring out how to control the randomness by a probability for example 50% (50) 25% (25) 25% (25) N=100.
to numberGenerator
let i 0
set counter_red 0
set counter_blue 0
set counter_green 0
while [i < 100] [
let numberS_red1 random-float 1
let numberS_blue1 random-float 1
let numberS_green1 random-float 1
let usedcolors [red blue green]
let OPstrength1 ( list numberS_red1 numberS_blue1 numberS_green1)
let strategies (map list usedcolors OPstrength1)
print strategies
if (numberS_red1 > numberS_blue1) and (numberS_red1 > numberS_green1)
[set counter_red counter_red + 1]
if (numberS_blue1 > numberS_red1) and (numberS_blue1 > numberS_green1)
[set counter_blue counter_blue + 1]
if (numberS_green1 > numberS_red1) and (numberS_green1 > numberS_blue1)
[set counter_green counter_green + 1]
set i i + 1
]
print counter_red
print counter_blue
print counter_green
end
counter_red = 26
counter_blue = 36
counter_green = 38
you can implement a new function using the netlogo random-normal command which assigns a color. Documentation for the function is at link
I have a number of global variables where values are set and a number of turtle-own variables where an initial value is set but change by the associated global variable once the model beings to run.
For example:
globals [dis-id]
turtles-own [identity]
to determine-parameters
set dis-id -1
ask turtles [
set identity 0
end
So when a turtle acts its identity goes up or down 1 depending on how successful an action has been.
So say an action was successful, identity should move from 0 to -1. If it is successful again it will move -1 to -2 etc. and vice-versa for failure 0 to 1, 1 to 2 etc.
My problem is that for every turtle that is added to the model (either created from the observer when running or setup procedure) this amount of change increases.
1 turtle 0 to 1, 1 to 2, 2 to 3 (correct + 1)
2 turtles 0 to 2, 2 to 4, 4 to 6 (incorrect + 2)
3 turtles 0 to 3, 3 to 6, 6 to 9 (incorrect + 3)
etc.
If the global variable is -6 instead of 1 i.e.
globals [dis-id]
turtle-own [identity]
to determine-parameters
set dis-id -6
ask turtles [
set identity 0
end
The same pattern occurs
1 turtle 0 to 6, 6 to 12, 12 to 18 (correct + 6)
2 turtles 0 to 12, 12 to 24, 24 to 36 (incorrect + 12)
3 turtles 0 to 18, 18 to 36, 36 to 54 (incorrect + 18)
etc.
The procedure/calculation to determine identity is
to succeed
ask turtles [
if outcome > expectation [
set identity (identity - dis-id)]
]
end
to fail
if outcome < expectation [
ask turtles [
set identity (identity - dis-id)]
]
end
This problem is consistent for every turtle-own variable calculated the same way.
I have attempted many fixes to no avail.
Any help with this would be much appreciated!
If any further explanation or code is needed to help problem solve this please let me know as I'm not sure how much or how little code I should put here. FYI the actual code is quite long.
UPDATE
the bit of code that was the problem was
to dothething
ask turtles [
if X >= Y [
succeed
fail]
]
Thank you to JenB for pointing this out!
I've been playing around with the diffuse keyword.
Consider the following 3x3 world where there's 3 chemical gradients at the top left corner and no chemical elsewhere. Also, there's no wrap on the edges.
[3 0 0 ]
[0 0 0 ]
[0 0 0 ]
If I have a diffusion rate of .5, I would expect that 3 (gradient) * .5 (diffusion rate) / 3 (#neighbors) = .5of the gradient would be given to its 3 neighbors. I would also expect that the original patch has 1.5 units remaining.
However, when I run the diffuse code, it seems that 3 (gradient) * .5 (diffusion rate) / 8 (#neighbors) = .1875 of the gradient is being set to the 3 neighbors. The original patch then has 2.4375 remaining units which isn't .5 of the original gradient. What's going on here? Is this an error or is my understanding incorrect?
See below:
patches-own [value]
to setup
cp
ask patch 0 2 [ set value 3]
diffuse value .5
ask patch 1 1 [ show value]
end
observer: show [value] of patches
observer: [0.1875 0.1875 0 2.4375 0 0 0 0.1875 0]
observer> ask patch 0 2 [ show count neighbors]
(patch 0 2): 3
One quick edit to your code is if you want the top left patch to have a value of 3, you need to ask patch 0 2. You're currently asking the bottom right patch.
Now, your issue is coming from the fact that when you diffuse, it tried to give 1.5 value away spread out over 8 patches, giving each neighboring patch 0.1875. Since your starting patch is in a corner is is only able to spread out across 3 patches and only gives away 0.5625 (3*.1825).
This leaves the original patch with 2.4375.
Note you do get your expected result if you allow the world to wrap around.
I want to try to draw stress and strain curve for copper nanoparticles with Lammps.
This is my code.
I don't know whether this is correct or not.
Can anybody help me?
It has fix nve for relaxation, but before that has fix nvt ,and these 2 fixes can't come together.
# tensile test
echo both
dimension 3
boundary s p p
units metal
atom_style atomic
##########create box#######
region copperbox block -80 80 -40 40 -40 40 units box
create_box 1 copperbox
lattice fcc 3.61
region copper block -60 60 -20 20 -20 20 units box
create_atoms 1 region copper
mass 1 63.546
thermo_modify lost ignore
region left block -60 -50 -20 20 -20 20 units box
group left region left
region right block 50 60 -20 20 -20 20 units box
group right region right
group middle subtract all left right
timestep 0.002
pair_style eam
pair_coeff * * cu_u3.eam
velocity all create 300 4928459 mom yes rot yes dist uniform
velocity left create 0 4928459 mom yes rot yes dist uniform
velocity right create 0 4928459 mom yes rot yes dist uniform
fix 1 all nvt temp 300 300 0.01
fix 2 left setforce 0 0 0
fix 3 right setforce 0 0 0
fix 4 all nve
thermo 100
run 1000
#####################################
compute 1 middle stress/atom
compute 2 middle reduce sum c_1[1]
dump 1 all custom 100 stress.txt mass x y z c_1[1] c_1[2] c_1[3]
c_1[4] c_1[5] c_1[6]
dump 2 all xyz 100 dump.xyz
#####################################
variable a loop 2
label loopa
fix 8 right move linear 0.2 0 0 units box
fix 9 left move linear 0 0 0 units box
run 1000
#####################################
unfix 8
unfix 9
fix 8 right move linear 0 0 0 units box
fix 9 left move linear 0 0 0 units box
run 40000
#####################################
fix 10 all nve
thermo 100
run 10000
#####################################
variable sigma equal "c_2/(40000)*(10^4)"
variable l2 equal xcm(right,x)
variable l0 equal ${l2}
variable strain equal "(v_l2-v_l0)/(v_l0)*100"
next a
jump in.copper99 loopa
restart 1000 restart.*
I'm plotting two surfaces in Matlab, the ground level which is constant and the water level which is changing in time.
I use an if statement to change the colormap of the water with increasing depth, determined by two thresholds (in the code below the thresholds are represented by the array C)
if max(C(:)) < 2
colormap([0.5 0.25 0 ; 0 0.8 1]);
elseif max(C(:)) >= 2 && max(C(:)) < 3
colormap([0.5 0.25 0 ; 0 0.8 1 ; 0 0.5 0.65]);
elseif max(C(:)) >= 3
colormap([0.5 0.25 0 ; 0 0.8 1 ; 0 0.5 0.65 ; 0 0.2 0.3]);
end
The result is that when the water level is below threshold 1 it is a light blue, between the two thresholds it turns darker, and above threshold 2 it turns darker yet.
My problem is that when I draw the legend
legend('ground','water');
... I only get one color representing the water, and it changes according to the max depth. How do I make a static legend showing all four categories with a color example:
(brown) Ground
(light blue) Water level beneath threshold 1
(standard blue) Water level between thresholds
(dark blue) Water level above threshold 2
The only solution I can think of is making 3 neat little patches somewhere by the axis (where it won't be noticed) in the right blue colors and then making the legend point at them and not the water surface. But that would be a real crappy solution...
You can display a colorbar():
C = [1 2 3 4];
if max(C(:)) < 2
colormap([0.5 0.25 0 ; 0 0.8 1]);
elseif max(C(:)) >= 2 && max(C(:)) < 3
colormap([0.5 0.25 0 ; 0 0.8 1 ; 0 0.5 0.65]);
elseif max(C(:)) >= 3
colormap([0.5 0.25 0 ; 0 0.8 1 ; 0 0.5 0.65 ; 0 0.2 0.3]);
end
% whatever to make your plot
imagesc(C);
% display a colorbar
cb_ax = colorbar;
% label it appropriately
set(cb_ax, 'YTick', [1:4]*3/4+5/8, 'YTickLabels', {'A', 'B', 'C', 'D'});