open loop theodolite

[Hans Blom, 970313]

Bill, can you please review the following program, after running it,
and tell me where I go wrong?

Greetings,

Hans

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
    if (c mod 10) = 0 then {show results}
      writeln (t:12:3, v:12:3, x1:12:3, x2:12:3, xa:12:3);
    v := v + a * dt; {this we agree on}
    x1 := x1 + v * dt; {my formula}
    x2 := x2 + v * dt + 0.5 * a * dt * dt; {your formula}
    xa := 0.5 * t * t; {exact solution}
    t := t + dt;
    c := c + 1;
  until t > 2.3
end.

···

a := 1.0; {constant acceleration}

Hi, Hans --At 06:33 PM 3/13/97 +0100, you wrote:

Bill, can you please review the following program, after running it,
and tell me where I go wrong?

Greetings,

Hans

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;
a := 1.0; {constant acceleration}
repeat

     {NOTE; THE EXACT SOLUTION FOR T = 0 HAS TO COME BEFORE PRINTOUT;
      X1, X2, AND V ARE ALREADY INITIALIZED FOR T = 0}
{=============================================================}

   xa := 0.5 * t * t; {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}

{NOTE: both of the above lines use the value of v at the start of the
interval. v should not be updated until just before the start of
the next interval}

{=============================================================}

   v := v + a * dt; {this we agree on}

{=============================================================}

   t := t + dt;
   c := c + 1;
until t > 2.3
end.

Now I think your results agree with mine.