Reputation: 1
I want to simulate n vehicles. Each vehicle is represented by a first discrete model:
P_i[k+1] = P_i[k] + T*v_i[k]
While P_i[k+1], P_i[k] respectively the position of vehicle i at sampling time (k+1)T and kT
T is the sampling time
v_i[k] is velocity of vehicle i at sampling time kT
The relation between vehicle is following the equation:
P_i[k+1] = T*(P_(i+1)[k+1] + P_(i-1)[k] - 2* P_i[k])
I don't know how to represent the sampling time T here
Upvotes: 0
Views: 84
Reputation: 17678
It is a little unclear what you mean by 'sampling time'. However, given your notation, I think you mean that T is current time, and you are calculating the position at the next point of time based on current position and velocity. In that case, you don't need to represent time explicitly, you only need to progress through it. In NetLogo tick
is the command to move forward one time step (and ticks
is the reporter for the number of time steps take so far, but I don't believe you need it).
UPDATED from comments:
I think we're talking at cross purposes. The point of sampling is to find a discrete approximation to a continuous function or set of functions. Once you are in discrete time, you can use tick as your time marker. Each tick, you can calculate the state. You just need to remember that you need to do (for example) 20 ticks to find the state at 10 seconds if you have a sampling time of 0.5 seconds.
Here is an example:
globals [ticks-per-sec]
turtles-own [velocity]
to setup
clear-all
set ticks-per-sec 2
create-turtles 10
[ setxy random-xcor random-ycor
set velocity (1 + random 4) / ticks-per-sec
set heading 90
]
reset-ticks
end
to go
ask turtles
[ forward velocity
set velocity 0.9 * velocity + 0.1 * mean [velocity] of other turtles
]
tick
end
I have set up all the turtles to head in the same direction so you can see their velocity converges. Your equations have a constant velocity, but this example is intended to show you how to have interaction between your vehicles.
Upvotes: 2