0

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

realgalois
  • 1
  • 1
  • 2

1 Answers1

2

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.

JenB
  • 17,620
  • 2
  • 17
  • 45
  • Thanks for your answer, the sampling time can be understand by that [definition](https://en.wikipedia.org/wiki/Sampling_(signal_processing) The tick time i think it does not have the same meaning with sampling time. For a fix sampling time (T) for example T= 0.5 s (after every 0.5 second we calculate all the state). – realgalois Feb 23 '18 at 14:41
  • 1
    Why do you think that tick doesn't have the same meaning? A tick can represent any arbitrary discrete time advance. If you use 1 tick = 0.5 seconds, then you will obviously need to convert in any report that includes time (eg seconds to resolution = simulation resolution ticks / 2). – JenB Feb 23 '18 at 15:55
  • you can take a look at this [reference](https://stackoverflow.com/questions/3571485/netlogo-1-tick-how-many-seconds) By the way do you know how to convert one tick = 0.5 seconds, I don't find any direct conversion – realgalois Feb 26 '18 at 08:07
  • For me : I use every command: to go every 0.5 ;; second [ do-stuff tick ] end – realgalois Feb 26 '18 at 08:12
  • I think that in discrete times system the state of the system is update every T (sampling time). So in your example it doesn't show the sampling meaning. Because the xcor, ycor is update after every tick not related to "tick-per-second" (variable). In the very shortime (sampling period) the velocity is constant. – realgalois Feb 28 '18 at 20:52
  • In my example, T is tick. The system is updated every tick (which is the same as every T). I don't need tick related to tick-per-second variable, a tick represents half a second. It doesn't matter whether the real computer time is 1 millisecond or 1 hour, the equations are advancing by half a second. – JenB Mar 01 '18 at 00:25