lyap.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { factory } from '../../utils/factory.js';
  2. var name = 'lyap';
  3. var dependencies = ['typed', 'matrix', 'sylvester', 'multiply', 'transpose'];
  4. export var createLyap = /* #__PURE__ */factory(name, dependencies, _ref => {
  5. var {
  6. typed,
  7. matrix,
  8. sylvester,
  9. multiply,
  10. transpose
  11. } = _ref;
  12. /**
  13. *
  14. * Solves the Continuous-time Lyapunov equation AP+PA'+Q=0 for P, where
  15. * Q is an input matrix. When Q is symmetric, P is also symmetric. Notice
  16. * that different equivalent definitions exist for the Continuous-time
  17. * Lyapunov equation.
  18. * https://en.wikipedia.org/wiki/Lyapunov_equation
  19. *
  20. * Syntax:
  21. *
  22. * math.lyap(A, Q)
  23. *
  24. * Examples:
  25. *
  26. * const A = [[-2, 0], [1, -4]]
  27. * const Q = [[3, 1], [1, 3]]
  28. * const P = math.lyap(A, Q)
  29. *
  30. * See also:
  31. *
  32. * sylvester, schur
  33. *
  34. * @param {Matrix | Array} A Matrix A
  35. * @param {Matrix | Array} Q Matrix Q
  36. * @return {Matrix | Array} Matrix P solution to the Continuous-time Lyapunov equation AP+PA'=Q
  37. */
  38. return typed(name, {
  39. 'Matrix, Matrix': function MatrixMatrix(A, Q) {
  40. return sylvester(A, transpose(A), multiply(-1, Q));
  41. },
  42. 'Array, Matrix': function ArrayMatrix(A, Q) {
  43. return sylvester(matrix(A), transpose(matrix(A)), multiply(-1, Q));
  44. },
  45. 'Matrix, Array': function MatrixArray(A, Q) {
  46. return sylvester(A, transpose(matrix(A)), matrix(multiply(-1, Q)));
  47. },
  48. 'Array, Array': function ArrayArray(A, Q) {
  49. return sylvester(matrix(A), transpose(matrix(A)), matrix(multiply(-1, Q))).toArray();
  50. }
  51. });
  52. });