exponential.lisp 1.91 KB
Newer Older
Liam Healy committed
1 2
;; Exponential of a matrix
;; Liam Healy 2008-08-10 17:25:35EDT exponential.lisp
3
;; Time-stamp: <2014-12-26 13:18:34EST exponential.lisp>
4
;;
5
;; Copyright 2008, 2009, 2010, 2014 Liam M. Healy
6 7 8 9 10 11 12 13 14 15 16 17 18 19
;; Distributed under the terms of the GNU General Public License
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
Liam Healy committed
20 21

(in-package :gsl)
22
(named-readtables:in-readtable :antik)
Liam Healy committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

;;; No documentation
(defmfun matrix-exponential (matrix exponential &optional (mode :double))
  "gsl_linalg_exponential_ss"
  (((mpointer matrix) :pointer) ((mpointer exponential) :pointer)
   (mode sf-mode))
  :inputs (matrix)
  :outputs (exponential)
  :documentation
  "Calculate the matrix exponential by the scaling and
   squaring method described in Moler + Van Loan,
   SIAM Rev 20, 801 (1978).  The matrix to be exponentiated
   is matrix, the returned exponential is exponential.
   The mode argument allows
   choosing an optimal strategy, from the table
   given in the paper, for a given precision.")

#|
;;; A matrix of the form [[0, 1], [-1, 0]]
;;; when exponentiated gives [[cos x,  sin x], [-sin x,  cos x]]
43
(let ((mat #m(0.0d0 1.0d0 ^ -1.0d0 0.0d0))
44
       (exp (grid:make-foreign-array 'double-float :dimensions '(2 2))))
45
  (grid:copy-to (matrix-exponential mat exp)))
Liam Healy committed
46 47 48
#2A((0.5403023058681384d0 0.841470984807895d0)
    (-0.841470984807895d0 0.5403023058681384d0))
|#