2928
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 // Written by A. S. Hodel <scotte@eng.auburn.edu> |
|
24 |
|
25 #ifdef HAVE_CONFIG_H |
|
26 #include <config.h> |
|
27 #endif |
|
28 |
|
29 #include "defun-dld.h" |
|
30 #include "error.h" |
|
31 #include "gripes.h" |
|
32 #include "oct-obj.h" |
|
33 #include "utils.h" |
|
34 |
|
35 DEFUN_DLD (expm, args, , |
|
36 "expm (X): matrix exponential, e^A") |
|
37 { |
|
38 octave_value_list retval; |
|
39 |
|
40 int nargin = args.length (); |
|
41 |
|
42 if (nargin != 1) |
|
43 { |
|
44 print_usage ("expm"); |
|
45 return retval; |
|
46 } |
|
47 |
|
48 octave_value arg = args(0); |
|
49 |
|
50 int nr = arg.rows (); |
|
51 int nc = arg.columns (); |
|
52 |
|
53 int arg_is_empty = empty_arg ("expm", nr, nc); |
|
54 |
|
55 if (arg_is_empty < 0) |
|
56 return retval; |
|
57 if (arg_is_empty > 0) |
|
58 return Matrix (); |
|
59 |
|
60 if (nr != nc) |
|
61 { |
|
62 gripe_square_matrix_required ("expm"); |
|
63 return retval; |
|
64 } |
|
65 |
|
66 if (arg.is_real_type ()) |
|
67 { |
|
68 Matrix m = arg.matrix_value (); |
|
69 |
|
70 if (error_state) |
|
71 return retval; |
|
72 else |
|
73 retval = m.expm (); |
|
74 } |
|
75 else if (arg.is_complex_type ()) |
|
76 { |
|
77 ComplexMatrix m = arg.complex_matrix_value (); |
|
78 |
|
79 if (error_state) |
|
80 return retval; |
|
81 else |
|
82 retval = m.expm (); |
|
83 } |
|
84 else |
|
85 { |
|
86 gripe_wrong_type_arg ("expm", arg); |
|
87 } |
|
88 |
|
89 return retval; |
|
90 } |
|
91 |
|
92 /* |
|
93 ;;; Local Variables: *** |
|
94 ;;; mode: C++ *** |
|
95 ;;; End: *** |
|
96 */ |