challenge -- my program

[From Bill Powers (950913.1100 MDT)]

Hans Blom (950913) --

Below is the code for my test program. I have set it up to compute the
reference signal and disturbance tables with varying slowing factors from
0.01 to 0.2. This affects the jumpiness of the tables and the degree of
control achieved. The routine for making the tables adjusts them to have an
average value of 0 and then to have a peak absolute value of 1000. The
output is simply a list of RMS differences between the controlled variable x
and the reference signal y for 10,000 iterations. The units in which RMS
error is shown are on a scale where the peak values of disturbance and
reference signal are 1000. The table that results for my model is

Slowing = 0.01 RMS ERROR = 0.5
Slowing = 0.02 RMS ERROR = 0.8
Slowing = 0.03 RMS ERROR = 1.2
Slowing = 0.04 RMS ERROR = 1.8
Slowing = 0.05 RMS ERROR = 2.5
Slowing = 0.06 RMS ERROR = 3.1
Slowing = 0.07 RMS ERROR = 4.1
Slowing = 0.08 RMS ERROR = 5.1
Slowing = 0.09 RMS ERROR = 6.0
Slowing = 0.10 RMS ERROR = 7.1
Slowing = 0.11 RMS ERROR = 8.1
Slowing = 0.12 RMS ERROR = 9.7
Slowing = 0.13 RMS ERROR = 10.9
Slowing = 0.14 RMS ERROR = 12.3
Slowing = 0.15 RMS ERROR = 13.5
Slowing = 0.16 RMS ERROR = 14.9
Slowing = 0.17 RMS ERROR = 17.1
Slowing = 0.18 RMS ERROR = 18.2
Slowing = 0.19 RMS ERROR = 20.7
Slowing = 0.20 RMS ERROR = 22.7

···

-------------------------------------------------
Best,

Bill P.

Program chalng1;

Uses dos, crt;

const maxtable = 9999;

var d,r: array[0..maxtable] of integer;
    x1,x2,x3,sum,u,x,b,slow: real;
    i,j: integer;
    ch: char;
    outfile: text;

function dist: real;
begin
x1 := maxtable + 10000.0*(random - 0.5);
x2 := x2 + slow * (x1 - x2);
x3 := x3 + slow * (x2 - x3);
dist := x3;
end;

procedure maketables;
var maxr,maxd: real;
begin

{MAKE DISTURBANCE TABLE AND ADJUST TO ZERO AVERAGE}

x1 := 0.0; x2 := 0.0; x3 := 0.0;

for i := 0 to maxtable do
d[i] := round(dist);
sum := 0.0;
for i := 0 to maxtable do
sum := sum + d[i];
sum := sum/(maxtable + 1);
for i := 0 to maxtable do
d[i] := d[i] - round(sum);

{MAKE REFERENCE TABLE AND ADJUST TO ZERO AVERAGE}

x1 := 0.0; x2 := 0.0; x3 := 0.0;

for i := 0 to maxtable do
r[i] := round(dist);

for i := 0 to maxtable do
sum := sum + r[i];
sum := sum/(maxtable + 1);
for i := 0 to maxtable do
r[i] := r[i] - round(sum);

{NORMALIZE D AND R TABLES TO PEAK VALUE OF 1000}

maxd := 0.0;
maxr := 0.0;

for i := 0 to maxtable do
begin
  if abs(d[i]) > maxd then maxd := abs(d[i]);
  if abs(r[i]) > maxr then maxr := abs(r[i]);
end;

for i := 0 to maxtable do
begin
  d[i] := round(1000.0*d[i]/maxd);
  r[i] := round(1000.0*r[i]/maxr);
end;

end;

              {Start main program}
begin
clrscr;
randomize;
assign(outfile,'challnge');
rewrite(outfile);

for j := 1 to 20 do
begin
slow := 0.01*j;
maketables;

sum := 0.0;
u := 0.0;
b := 1.00;

               {RUN THE MODEL MAXTABLE + 1 TIMES}
{==============================================================}
for i := 0 to maxtable do
begin
  x := u + d[i]; { ENVIRONMENT}
  u := u + b * (r[i] - x); { MODEL }
  sum := sum + sqr(r[i] - x); { ACCUMULATE FOR RMS CALCULATION}
end;
{==============================================================}

  sum := sqrt(sum / (maxtable + 1));
  writeln(outfile,'Slowing = ',slow:5:2,' RMS ERROR = ',sum:4:1);
  writeln('Slowing = ',slow:5:2,' RMS ERROR = ',sum:4:1);

end; { of loop for changing slowing factor}

writeln('STRIKE ANY KEY TO EXIT');
close(outfile);
ch := readkey;
end.