home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / languages / rlab1_23a / CTB / lqrymsf < prev    next >
Encoding:
Text File  |  1995-11-15  |  2.1 KB  |  82 lines

  1. //----------------------------------------------------------------------------
  2. //
  3. // lqrymsf
  4. //
  5. // Symsfntax: G=lqrymsf(A,B,C,D,Q,R,Reps,iterm)
  6. //
  7. // This routine computes the Linear Quadratic Design for Continuous Systems
  8. // with weighting on the outputs. It calculates the optimal feedback gain
  9. // matrix K such that the feedbakc law u = -Kx minimizes the following
  10. // cost function:
  11. //
  12. //           Inf
  13. //     J = Integral ( y'Qy + u'Ru ) dt
  14. //            0
  15. //
  16. // subject to the constraint
  17. //
  18. //   .
  19. //   x = Ax + Bu
  20. //   y = Cx + Du
  21. //
  22. // It uses the matrix sign function (msf) technique to solve the Riccati
  23. // equation necessary to compute the gains. The input Reps is the tolerance
  24. // for the iteration procedure and the variable iterm is the maximum
  25. // number of iterations.
  26. //
  27. //
  28. // Note: Three matrices are returned in a list.
  29. //
  30. //       G.k = Optimal Feedback Gain matrix
  31. //       G.s = Steady-State Solution to the Algebraic Riccatti Eqn.
  32. //
  33. //  Ref.: (1) Chapter 5 of Junkins & Kim, Dyn. & Ctrl. of Structures.
  34. //        (2) Bierman, G.J.,
  35. //            "Computational Aspects of the Matrix Sign Function to the ARE"
  36. //            Proc. 23rd CDC, 1984, pp.514-519.
  37. //
  38. // Copyright (C), by Jeffrey B. Layton, 1994
  39. // Version JBL 940918
  40. //----------------------------------------------------------------------------
  41.  
  42. rfile lqrmsf
  43.  
  44. lqrymsf = function(a,b,c,d,q,r,Reps,iterm)
  45. {
  46.    local(nargs,t,itermax,eps)
  47.  
  48. // Count number of input arguments
  49.    nargs=0;
  50.    if (exist(a)) {nargs=nargs+1;}
  51.    if (exist(b)) {nargs=nargs+1;}
  52.    if (exist(c)) {nargs=nargs+1;}
  53.    if (exist(d)) {nargs=nargs+1;}
  54.    if (exist(q)) {nargs=nargs+1;}
  55.    if (exist(r)) {nargs=nargs+1;}
  56.    if (exist(Reps)) {nargs=nargs+1;}
  57.    if (exist(iterm)) {nargs=nargs+1;}
  58.  
  59.    if (nargs < 6 ) {
  60.        error("LQRY: Wrong number of input arguments.");
  61.    }
  62.  
  63. // Set defaults if variables are not input.
  64. // ========================================
  65.  
  66.    if (!exist(iterm)) {
  67.        itermax=1000;
  68.    else
  69.        itermax=iterm;
  70.    }
  71.  
  72.    if (!exist(Reps)) {
  73.        eps=1.0e-10;
  74.    else
  75.        eps=Reps
  76.    }
  77.  
  78.    t=lqrmsf(a,b, c'*q*c, r+d'*q*d, eps, itermax, c'*q*d);
  79.  
  80.    return << k=t.G; s=t.P >>
  81. };
  82.