50
|
1 /* |
|
2 |
1884
|
3 Copyright (C) 1996 John W. Eaton |
50
|
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 |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
50
|
20 |
|
21 */ |
|
22 |
|
23 // Written by A. S. Hodel <scotte@eng.auburn.edu> |
|
24 |
240
|
25 #ifdef HAVE_CONFIG_H |
1192
|
26 #include <config.h> |
50
|
27 #endif |
|
28 |
1352
|
29 #include "defun-dld.h" |
|
30 #include "error.h" |
|
31 #include "gripes.h" |
|
32 #include "help.h" |
1740
|
33 #include "oct-obj.h" |
636
|
34 #include "utils.h" |
50
|
35 |
1957
|
36 DEFUN_DLD_BUILTIN (expm, args, , |
519
|
37 "expm (X): matrix exponential, e^A") |
50
|
38 { |
2086
|
39 octave_value_list retval; |
519
|
40 |
|
41 int nargin = args.length (); |
|
42 |
712
|
43 if (nargin != 1) |
519
|
44 { |
|
45 print_usage ("expm"); |
|
46 return retval; |
|
47 } |
|
48 |
2086
|
49 octave_value arg = args(0); |
50
|
50 |
636
|
51 int nr = arg.rows (); |
|
52 int nc = arg.columns (); |
|
53 |
718
|
54 int arg_is_empty = empty_arg ("expm", nr, nc); |
|
55 |
|
56 if (arg_is_empty < 0) |
636
|
57 return retval; |
718
|
58 if (arg_is_empty > 0) |
|
59 return Matrix (); |
636
|
60 |
|
61 if (nr != nc) |
50
|
62 { |
636
|
63 gripe_square_matrix_required ("expm"); |
|
64 return retval; |
50
|
65 } |
636
|
66 |
|
67 if (arg.is_real_type ()) |
|
68 { |
|
69 Matrix m = arg.matrix_value (); |
|
70 |
|
71 if (error_state) |
|
72 return retval; |
1819
|
73 else |
|
74 retval = m.expm (); |
636
|
75 } |
|
76 else if (arg.is_complex_type ()) |
|
77 { |
|
78 ComplexMatrix m = arg.complex_matrix_value (); |
|
79 |
|
80 if (error_state) |
|
81 return retval; |
1819
|
82 else |
|
83 retval = m.expm (); |
636
|
84 } |
|
85 else |
|
86 { |
|
87 gripe_wrong_type_arg ("expm", arg); |
|
88 } |
50
|
89 |
|
90 return retval; |
|
91 } |
|
92 |
|
93 /* |
|
94 ;;; Local Variables: *** |
|
95 ;;; mode: C++ *** |
|
96 ;;; End: *** |
|
97 */ |