home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / r / rlab / CTB / are2test < prev    next >
Encoding:
Text File  |  1995-11-15  |  1.4 KB  |  73 lines

  1. //-----------------------------------------------------------------------------
  2. // ****************
  3. // * ARE2 Testing *
  4. // ****************
  5. // Ref: MATLAB Control Toolbox Manual
  6. // Ref: Laub, A. J., "A Schur Method for Solving Algebraic Riccati
  7. //      Equations," IEEE Trans. AC-24, 1979, pp. 913-921.
  8. //
  9. // Version JBL 950106
  10. //
  11.  
  12. rfile lqr
  13. rfile are2
  14. rfile banner
  15.  
  16. // =============================================
  17. //                     Test 1:
  18. // =============================================
  19.  
  20. printf("%s"," \n");
  21. banner("Test1");
  22.  
  23. A=[0,1;0,0];
  24. B=[0;1];
  25. R=[1];
  26. Q=[1,0;0,2];
  27.  
  28. P=[2,1;1,2];
  29.  
  30. Barg=B*inv(R)*B';
  31. Carg=Q;
  32. P2=are2(A,Barg,Carg);
  33.  
  34. // Check norm of the error
  35. Pnorm=norm(P-P2);
  36. printf ("ARE2 check (this matrix ought to be SMALL)\n");
  37. P-P2
  38. printf("%s","Norm of solution error = ");
  39. sprintf(sdum,"%12.5e",Pnorm);
  40. s="   "+sdum;
  41. printf("%s\n",s);
  42.  
  43. // =============================================
  44. //                     Test 2:
  45. // =============================================
  46.  
  47. printf("%s"," \n");
  48. banner("Test2");
  49.  
  50. A=[4,3;-(9/2),-(7/2)];
  51. B=[1;-1];
  52. R=[1];
  53. Q=[9,6;6,4];
  54.  
  55. // RLaB lqr routine solution
  56. X=lqr(A,B,Q,R);
  57. P=X.p;
  58.  
  59. Barg=B*inv(R)*B';
  60. Carg=Q;
  61. P2=are2(A,Barg,Carg);
  62.  
  63. // Check norm of the error
  64. Pnorm=norm(P-P2);
  65. printf ("ARE2 check (this matrix ought to be SMALL)\n");
  66. P-P2
  67. printf("%s","Norm of solution error = ");
  68. sprintf(sdum,"%12.5e",Pnorm);
  69. s="   "+sdum;
  70. printf("%s\n",s);
  71. printf("%s"," \n");
  72.  
  73.