Implements the discrete Kalman Filtering Equations for Exercise 8

zhat[
          i_] := xip1Giveni[i - 1];

    s[i_] := cip1Giveni[i - 1] + v;

    k[i_] := 
        cip1Giveni[i - 1]/(cip1Giveni[i - 1] + v);

    xiGiveni[i_] := 
        xip1Giveni[i - 1] + k[i] (z[i] - zhat[i]);

    ciGiveni[i_] := v k[i];


    xip1Giveni[i_] := a xiGiveni[i];

    cip1Giveni[i_] := (a^2) ciGiveni[i] + w;

zhat[0] = 0;

    s[0] = 1000;

    k[0] = 1;

    xiGiveni[0] = z[0];

    ciGiveni[0] = v;

    xip1Giveni[0] = a z[0];

    cip1Giveni[0] = (a^2) v + w;

{zhat[
          1], 
s[1], 
k[
          1], 
xiGiveni[1], 
ciGiveni[
          1], 
xip1Giveni[1], 
cip1Giveni[
          1]} // Simplify

(* 
      compute the above expressions for the next value of i *) 
i = 2;

    {zhat[i], 
s[i], 
k[
          i], 
xiGiveni[i], 
ciGiveni[
          i], 
xip1Giveni[i], 
cip1Giveni[
          i]} // Simplify

(* 
      compute the above expressions for the next value of i *) 
i = 3;

    {zhat[i], 
s[i], 
k[
          i], 
xiGiveni[i], 
ciGiveni[
          i], 
xip1Giveni[i], 
cip1Giveni[
          i]} // Simplify

RSolve[{c[
                i + 1] == (v^2) (a^2) (c[i]/(c[i] + (v^2))) + (w^2), c[0] == (a^2) (v^2) + (w^2)}, c[i], i] // 
        Simplify;

RSolve[{d[i + 1] == (a^2) (d[i]/(d[i] + 1)) + r, 
          d[0] == (a^2) + r}, d[i], i] // Simplify

Factor[-4 (a^2) + (((1 + (a^2) + r))^2)]