comparison main/linear-algebra/funm.m @ 0:6b33357c7561 octave-forge

Initial revision
author pkienzle
date Wed, 10 Oct 2001 19:54:49 +0000
parents
children 2ac2777b30bc
comparison
equal deleted inserted replaced
-1:000000000000 0:6b33357c7561
1 ## Copyright (C) 2000 P.R. Nienhuis
2 ##
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2, or (at your option)
6 ## any later version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ## General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; see the file COPYING. If not, write to the
15 ## Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
16 ## 02111-1307, USA.
17
18 ## funm: Matrix equivalent of function 'name'
19 ##
20 ## Usage: B = funm(A, name)
21 ## where A = square non-singular matrix, provisionally
22 ## real-valued
23 ## B = square result matrix
24 ## name = string, name of function to apply to A.
25 ## args = any arguments to pass to function 'name'
26 ## The function must accept a vector and apply
27 ## element-wise to that vector.
28 ##
29 ## Example: To compute sqrtm(A), you could use funm(A, 'sqrt')
30 ##
31 ## Note that you should not use funm for 'sqrt', 'log' or 'exp'; instead
32 ## use sqrtm, logm and expm which are more robust. Similarly,
33 ## trigonometric and hyperbolic functions (cos, sin, tan, cot, sec, csc,
34 ## cosh, sinh, tanh, coth, sech, csch) are better handled by thfm(A,
35 ## name), which defines them in terms of the more robust expm.
36
37 ## NOTE: the following comments are withheld until they can be verified
38 ##
39 ## If you have a network of coupled systems, where for the individual
40 ## systems a solution exists in terms of scalar variables, in many
41 ## cases the network might be solved using the same form of the
42 ## solution but with substituting the matrix equivalent of the function
43 ## applied to the scalar variables.
44 ## The approach is to do an eigen-analysis of the network to decouple
45 ## the systems, apply the scalar functions to the eigenvalues,
46 ## and then recombine the systems into a network.
47
48 ## Author: P.R. Nienhuis, 106130.1515@compuserve.com
49 ## Additions by P. Kienzle, .........
50 ## 2001-03-01 Paul Kienzle
51 ## * generate error for repeated eigenvalues
52
53 function B = funm(A, name)
54
55 if (nargin != 2 || !isstr(name) || isstr(A))
56 usage ("B = funm (A, 'f' [, args])");
57 endif
58
59 [V, D] = eig (A);
60 D = diag (feval (name, diag(D)));
61 B = V * D * inv (V);
62
63 endfunction