open loop theodolite: correct the correction

[Hans Blom, 970318]

Bill, thanks for the help in correcting my open loop theodolite
program. I must have had a blind spot when I made the test program.
Your correction is, indeed, exact -- but only in this example...

To give others an idea of the models' performances: when the "unit"
theodolite (J=1) is given a constant acceleration a=1, its true
position after 2 seconds is 2. Bill's model also gives this same
result, independent of the value of dt, whereas my model gives the
following results:

dt=0.1 x=1.900 error=0.1
dt=0.01 x=1.990 error=0.01
dt=0.001 x=1.999 error=0.001

There is, however, a problem with Bill's extra correction term: it is
exact only in this particular example. The following program gives a
demonstration; now the acceleration is not constant but increases
linearly with time (a=t). Three solutions are printed by the program,
the exact one, and the results of Bill's and my own formulas.

program open_loop_theodolite;
var
  a, v, xa, x1, x2, t, dt: real;
  c: integer;
begin
  c := 0; dt := 0.01;
  x1 := 0.0; x2 := 0.0;
  v := 0.0; t := 0.0;
  repeat
    xa := t * t * t / 6.0; {exact solution}
    if (c mod 10) = 0 then {show results}
      writeln (t:12:3, v:12:3, x1:12:3, x2:12:3, xa:12:3);
    x1 := x1 + v * dt; {my formula}
    x2 := x2 + v * dt + 0.5 * a * dt * dt; {your formula}
    v := v + a * dt; {this we agree on}
    t := t + dt;
    c := c + 1;
  until t > 2.0001
end.

If we look at the outcome after 2 seconds again, we find that the
true solution of the differential equation is x = 8/6 = 1.333,
whereas the results of Bill's and my formulas are

         Hans Bill
dt=0.1 1.140 1.235
dt=0.01 1.313 1.323
dt=0.001 1.331 1.332

Now Bill's solution isn't exact either, and _is_ dependent on the
choice of dt. A general feature of both models is that, as expected,
they become more accurate as dt decreases.

Is all this relevant? Yes. The theodolite controller does not operate
under conditions of constant acceleration. The program above
demonstrates that, contrary to what Bill intuited, it is not possible
_generally_ to translate a differential equation model into an
exactly equivalent difference equation model. Modeling/sampling
theory says so, and the program above gives an example. If an exact
equivalent _were_ possible, designers of programs such as Simcon,
Tutsim and Matlab wouldn't have the problems they do have. Their
solution is invariably to choose a sufficiently small dt (on the fly,
preferably).

Is all this talk about a "correction term" relevant? Not really. In
the theodolite controller, we happened to stipulate a control
trajectory where -- if control would be exact -- the acceleration
would be zero almost everywhere (because either x must be constant or
v must be constant), except in 4 discrete points (when the theodolite
is given its speed and when it stops, and when the disturbance starts
and when it ends). Thus, due to the control, in the actual theodolite
controller Bill's correction term 0.5*a*dt*dt turns out to be zero or
almost zero almost everywhere -- and can effectively be neglected, as
the MCT controller demonstrated with its almost perfect control.
Bill's "correction term" simply cannot explain the failure of his
implementation of the MCT controller. There must be another reason...

But first things first. Bill, do you want to try again in finding an
"exact" (acceleration independent) theodolite model that we should
use to generate the MCT and PCT controller's perceptions? Warning:
theory says that no exact computer model is possible; only
approximations, whose quality improves as dt decreases, are. But
theory isn't holy, of course ;-). Want to try again and correct the
correction term?

Other readers may think this is much ado about nothing. Maybe it is.
Yet, dotting an i may provide some insight, occasionally.

Greetings,

Hans

···

a := t; {linearly increasing acceleration}

[From Bill Powers (970318.1115 MST)]

Hans Blom, 970318--

Bill, thanks for the help in correcting my open loop theodolite
program. I must have had a blind spot when I made the test program.
Your correction is, indeed, exact -- but only in this example...

There is, however, a problem with Bill's extra correction term: it is
exact only in this particular example. The following program gives a
demonstration; now the acceleration is not constant but increases
linearly with time (a=t). Three solutions are printed by the program,
the exact one, and the results of Bill's and my own formulas.

I wish you'd stop calling this a "correction term". It is simply the right
way to represent the solution of the differential equation. I'm not making
it up just to get a lucky right answer; I'm going through the calculus
manipulations.

Your new program uses a new acceleration proportional to time. This requires
a new solution of the differential equations, which I have tediously worked
out (not being very good at this); you have to find the integral and then
evaluate it from time t to t + DT, and now we're dealing with cubic
equations. After filling about eight sheets of paper trying to get it right,
I ended up with the appended program, which again gives the exact position.

All we're doing here is finding the iterative form for the theodolite
equation; if it's correct, it should give exactly the same result as
computing x = t^3/6. I repeat once again that this solution is correct only
if the torque is applied in steps, being constant between steps. This has
nothing to do with the controller -- yet.

Look, Hans, if you've forgotten your calculus, just say so. I don't know
what you're trying to prove here.

Is all this talk about a "correction term" relevant? Not really. In
the theodolite controller, we happened to stipulate a control
trajectory where -- if control would be exact -- the acceleration
would be zero almost everywhere (because either x must be constant or
v must be constant), except in 4 discrete points (when the theodolite
is given its speed and when it stops, and when the disturbance starts
and when it ends). Thus, due to the control, in the actual theodolite
controller Bill's correction term 0.5*a*dt*dt turns out to be zero or
almost zero almost everywhere -- and can effectively be neglected, as
the MCT controller demonstrated with its almost perfect control.

We haven't even got to the MCT model yet. My "correction term" applies to
the real theodolite, and is necessary to represent its response to the
controller's output correctly. It is _neglecting_ this term that makes your
MCT model seem to work perfectly. You will find out, if you let us go on,
that the MCT model using the _correct_ response of the theodolite does NOT
work perfectly. Your use of an approximation both inside and outside the MCT
model introduces a fudge factor. But I don't want to argue at that level;
let's just go on and demonstrate what I mean, making sure at each step that
I am applying the principles of the MCT approach correctly.

Best,

Bill P.

···

========================================================================
program open_loop_theodolite_2;
uses dos,crt;
var
  a, v1, v2, va, xa, x1, x2, t, dt: real;
  c: integer;
  ch: char;
begin
  clrscr;
  c := 0; dt := 0.01;
  x1 := 0.0; x2 := 0.0;
  v1 := 0.0; v2 := 0.0; t := 0.0;
  writeln('TIME':8,'V1':10,'V2':10,'VA':10,'X1':10,'X2':10,'XA':10);
  repeat
    a := t; {linearly increasing acceleration}
    xa := t * t * t / 6.0; {exact solution}
    va := t*t/2.0; {EXACT VELOCITY}
    if (c mod 10) = 0 then {show results}
writeln (t:10:5, v1:10:5, v2:10:5, va:10:5, x1:10:5, x2:10:5, xa:10:5);
    x1 := x1 + v1 * dt; {my formula}
    v1 := v1 + a * dt; {this we agree on}{NOT ANY MORE}
    x2 := x2 + v2 * dt + (t*dt*dt + dt*dt*dt/3.0)/2.0; {MY NEW X}
    v2 := v2 + (2.0*t*dt + dt*dt)/2.0; {MY NEW VELOCITY}
    t := t + dt;
    c := c + 1;
  until t > 2.0001;
  ch := readkey;
end.

program open_loop_theodolite;
var
a, v, xa, x1, x2, t, dt: real;
c: integer;
begin
c := 0; dt := 0.01;
x1 := 0.0; x2 := 0.0;
v := 0.0; t := 0.0;
repeat
   a := t; {linearly increasing acceleration}
   xa := t * t * t / 6.0; {exact solution}
   if (c mod 10) = 0 then {show results}
     writeln (t:12:3, v:12:3, x1:12:3, x2:12:3, xa:12:3);
   x1 := x1 + v * dt; {my formula}
   x2 := x2 + v * dt + 0.5 * a * dt * dt; {your formula}
   v := v + a * dt; {this we agree on}
   t := t + dt;
   c := c + 1;
until t > 2.0001
end.

If we look at the outcome after 2 seconds again, we find that the
true solution of the differential equation is x = 8/6 = 1.333,
whereas the results of Bill's and my formulas are

        Hans Bill
dt=0.1 1.140 1.235
dt=0.01 1.313 1.323
dt=0.001 1.331 1.332

Now Bill's solution isn't exact either, and _is_ dependent on the
choice of dt. A general feature of both models is that, as expected,
they become more accurate as dt decreases.

Is all this relevant? Yes. The theodolite controller does not operate
under conditions of constant acceleration. The program above
demonstrates that, contrary to what Bill intuited, it is not possible
_generally_ to translate a differential equation model into an
exactly equivalent difference equation model. Modeling/sampling
theory says so, and the program above gives an example. If an exact
equivalent _were_ possible, designers of programs such as Simcon,
Tutsim and Matlab wouldn't have the problems they do have. Their
solution is invariably to choose a sufficiently small dt (on the fly,
preferably).

Bill's "correction term" simply cannot explain the failure of his
implementation of the MCT controller. There must be another reason...