% Script file to solve question 4 from the homework.
%
% Ian Mitchell for CPSC 532M, 5/4/08.

  % Common parameters for both parts.
  tf = 10;
  x0 = [ 0; 1 ];
  
  % In part (a) we use fix stepsize and discrete LQR.
  h = 0.25;
  
  A_a = [ +1, -h; +h, +1 ];
  B_a = 0.5 * h * [ sqrt(3); 1 ];
  Q_a = h * eye(2);
  Qf_a = Q_a;
  R_a = h;
  
  discreteLQR(A_a, B_a, Q_a, R_a, h, Qf_a, tf, x0);
  
  % In part (b) we use the continuous LQR.
  A_b = [ 0, -1; +1, 0 ];
  B_b = 0.5 * [ sqrt(3); 1 ];
  Q_b = eye(2);
  Qf_b = Q_b;
  R_b = 1;
  
  continuousLQR(A_b, B_b, Q_b, R_b, Qf_b, tf, x0);
  
  
