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

  1.  
  2. // This routine tests the continuous lqr solution methods using examples
  3. // from Laub's paper.
  4.  
  5. rfile banner
  6. rfile lqr
  7. rfile lqrmsf
  8.  
  9. banner("Continuous lqr QA");
  10. // =============================================
  11. //                     Test 1:
  12. // =============================================
  13.  
  14. printf("%s"," \n");
  15. banner("Test1");
  16.  
  17. A=[0,1;0,0];
  18. B=[0;1];
  19. R=[1];
  20. Q=[1,0;0,2];
  21.  
  22. // Exact Solution
  23. Xsolution=[2,1;1,2];
  24.  
  25. // RLaB lqr routine solution
  26. X=lqr(A,B,Q,R);
  27.  
  28. // RLaB lqrmsf routine solution
  29. X2=lqrmsf(A,B,Q,R);
  30.  
  31. // Check norm of the error
  32. Xnorm=norm(Xsolution-X.p);
  33. X2norm=norm(Xsolution-X2.P);
  34. printf("%s","Norm of solution error = ");
  35. sprintf(sdum,"%12.5e",Xnorm);
  36. s="   "+sdum;
  37. printf("%s\n",s);
  38. X2norm
  39.  
  40. // =============================================
  41. //                     Test 2:
  42. // =============================================
  43.  
  44. printf("%s"," \n");
  45. banner("Test2");
  46.  
  47. A=[4,3;-(9/2),-(7/2)];
  48. B=[1;-1];
  49. R=[1];
  50. Q=[9,6;6,4];
  51.  
  52. // Exact Solution
  53. c=1.0+sqrt(2);
  54. Xsolution=[9*c,6*c;6*c,4*c];
  55.  
  56. // RLaB lqr routine solution
  57. X=lqr(A,B,Q,R);
  58.  
  59. // RLaB lqrmsf routine solution
  60. X2=lqrmsf(A,B,Q,R);
  61.  
  62. // Check norm of the error
  63. Xnorm=norm(Xsolution-X.p);
  64. printf("%s","Norm of solution error = ");
  65. sprintf(sdum,"%12.5e",Xnorm);
  66. s="   "+sdum;
  67. printf("%s\n",s);
  68. X2norm=norm(Xsolution-X2.P)
  69.