SCREEN 12 PRINT "Simulation of closed-loop system with `live input'" PRINT INPUT "Feedback, damping (suggest 8,2 to start) "; f, d CLS VIEW (2, 20)-(638, 328), 8, 4 WINDOW (-.5, -2.5)-(20.5, 2.5) LINE (0, 0)-(20, 0), 1 PRINT "Press number keys 0 to 9 to change the target" ' dt = .00005 'Make dt larger to speed up running ulim = 4 x = 1 'Initial values v = 0 t = 0 target = -1 'initial target until a key is pressed PSET (0, x) 'move to the first point DO COLOR 15 a$ = INKEY$ IF a$ <> "" THEN target = .4 * VAL(a$) - 2 u = f * (target - x) - d * v 'u is determined by feedback IF u > ulim THEN u = ulim COLOR 12 ELSEIF u < -ulim THEN u = -ulim COLOR 12 END IF x = x + v * dt 'This is the simulation v = v + u * dt ' t = t + dt LINE -(t, x) 'This displays the result LOOP UNTIL t > 20 '