# challenge results

[Hans Blom, 950914x]

Faster than I thought. Bill, your code was easy to modify (thanks!).
Here are the results of our little competition:

The results of the original problem:

HANS BILL
Slowing = 0.01 RMS ERROR = 0.5 RMS ERROR = 0.5
Slowing = 0.02 RMS ERROR = 0.7 RMS ERROR = 0.8
Slowing = 0.03 RMS ERROR = 0.8 RMS ERROR = 1.3
Slowing = 0.04 RMS ERROR = 0.9 RMS ERROR = 1.8
Slowing = 0.05 RMS ERROR = 1.0 RMS ERROR = 2.5
Slowing = 0.06 RMS ERROR = 1.3 RMS ERROR = 3.3
Slowing = 0.07 RMS ERROR = 1.6 RMS ERROR = 4.0
Slowing = 0.08 RMS ERROR = 2.1 RMS ERROR = 4.9
Slowing = 0.09 RMS ERROR = 2.6 RMS ERROR = 5.9
Slowing = 0.10 RMS ERROR = 3.2 RMS ERROR = 7.3
Slowing = 0.11 RMS ERROR = 3.9 RMS ERROR = 8.2
Slowing = 0.12 RMS ERROR = 4.6 RMS ERROR = 9.3
Slowing = 0.13 RMS ERROR = 5.4 RMS ERROR = 10.5
Slowing = 0.14 RMS ERROR = 6.4 RMS ERROR = 12.1
Slowing = 0.15 RMS ERROR = 7.4 RMS ERROR = 13.5
Slowing = 0.16 RMS ERROR = 8.5 RMS ERROR = 15.1
Slowing = 0.17 RMS ERROR = 9.7 RMS ERROR = 16.6
Slowing = 0.18 RMS ERROR = 11.1 RMS ERROR = 18.6
Slowing = 0.19 RMS ERROR = 12.2 RMS ERROR = 20.2
Slowing = 0.20 RMS ERROR = 13.8 RMS ERROR = 21.9

After your suggested correction of the first line of function dist:

HANS BILL
Slowing = 0.01 RMS ERROR = 2.1 RMS ERROR = 6.6
Slowing = 0.02 RMS ERROR = 2.1 RMS ERROR = 10.4
Slowing = 0.03 RMS ERROR = 4.5 RMS ERROR = 13.8
Slowing = 0.04 RMS ERROR = 3.8 RMS ERROR = 18.0
Slowing = 0.05 RMS ERROR = 8.4 RMS ERROR = 22.3
Slowing = 0.06 RMS ERROR = 9.3 RMS ERROR = 24.6
Slowing = 0.07 RMS ERROR = 11.6 RMS ERROR = 31.5
Slowing = 0.08 RMS ERROR = 12.4 RMS ERROR = 36.3
Slowing = 0.09 RMS ERROR = 15.0 RMS ERROR = 40.7
Slowing = 0.10 RMS ERROR = 16.9 RMS ERROR = 39.3
Slowing = 0.11 RMS ERROR = 21.5 RMS ERROR = 49.0
Slowing = 0.12 RMS ERROR = 24.7 RMS ERROR = 48.9
Slowing = 0.13 RMS ERROR = 24.2 RMS ERROR = 57.7
Slowing = 0.14 RMS ERROR = 32.3 RMS ERROR = 60.6
Slowing = 0.15 RMS ERROR = 37.4 RMS ERROR = 62.1
Slowing = 0.16 RMS ERROR = 38.1 RMS ERROR = 67.7
Slowing = 0.17 RMS ERROR = 46.1 RMS ERROR = 78.7
Slowing = 0.18 RMS ERROR = 53.3 RMS ERROR = 82.5
Slowing = 0.19 RMS ERROR = 40.8 RMS ERROR = 75.5
Slowing = 0.20 RMS ERROR = 56.6 RMS ERROR = 87.2

The code where I put my changes (except for some declarations of the
new variables that I need) is:

{RUN THE MODEL MAXTABLE + 1 TIMES}
{==============================================================}
dold := 0.0; { we have no value d [-1] }
for i := 0 to maxtable do
begin
x := u + d[i]; { ENVIRONMENT}

{at this point, the observation x[i] and the control u[i] are known}
dnew := x - u; { recreate disturbance d[i] }
dpre := 2.0 * dnew - dold; { predict next disturbance d[i+1] }
u := r [i+1] - dpre; { compute control u[i+1]; note that
u[i+1] is applied in the next iter-
ation, at time i+1, when r [i+1] is
known }
dold := dnew; { save previous disturbance }
if i > 1 then { allow for learning start up }
sum := sum + sqr(r[i] - x); { ACCUMULATE FOR RMS CALCULATION}
end;
{==============================================================}

The only change I made to your code is in the accumulation for the
RMS error. That is because my algorithm needs to start up its
learning. To be fair, I added the same "if i > 1 then" to your code
before doing the comparison.

Primitive in this program is the prediction of the next disturbance
d[i+1]. Much better methods are available. But they seem not to be
necessary for this problem, because the basic first order hold works
well.

Can you explain (in words) what "slowing" does? It doesn't fit into
my concepts for model-based control. Yet it makes a difference.

Are things clearer now?

Rick, are you satisfied too?

Greetings,

Hans