]> Creatis software - CreaPhase.git/blob - octave_packages/dataframe-0.9.1/@dataframe/inv.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / dataframe-0.9.1 / @dataframe / inv.m
1 function [resu, rcond] = inv(df);
2
3   %# function [x, rcond] = inv(df)
4   %# Overloaded function computing the inverse of a dataframe. To
5   %# succeed, the dataframe must be convertible to an square array. Row
6   %# and column meta-information are exchanged.  
7
8   %% Copyright (C) 2009-2012 Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
9   %%
10   %% This file is part of Octave.
11   %%
12   %% Octave is free software; you can redistribute it and/or
13   %% modify it under the terms of the GNU General Public
14   %% License as published by the Free Software Foundation;
15   %% either version 2, or (at your option) any later version.
16   %%
17   %% Octave is distributed in the hope that it will be useful,
18   %% but WITHOUT ANY WARRANTY; without even the implied
19   %% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20   %% PURPOSE.  See the GNU General Public License for more
21   %% details.
22   %%
23   %% You should have received a copy of the GNU General Public
24   %% License along with Octave; see the file COPYING.  If not,
25   %% write to the Free Software Foundation, 51 Franklin Street -
26   %% Fifth Floor, Boston, MA 02110-1301, USA.
27   
28   %#
29   %# $Id: inv.m 9585 2012-02-05 15:32:46Z cdemills $
30   %#
31
32   if (length(df._cnt) > 2 || (df._cnt(1) != df._cnt(2))),
33     error("Dataframe is not square");
34   endif
35
36   %# quick and dirty conversion
37   [dummy, rcond] = inv(horzcat(df._data{:}));
38
39   resu = df_allmeta(df);
40   
41   [resu._name{2}, resu._name{1}] = deal(resu._name{1}, resu._name{2});
42   [resu._over{2}, resu._over{1}] = deal(resu._over{1}, resu._over{2});
43   if (isempty(resu._name{2})),
44     resu._name{2} = cellstr(repmat('_', resu._cnt(2), 1));
45     resu._over{2} = ones(1, resu._cnt(2));
46   endif
47   for indi = resu._cnt(1):-1:1,
48     resu._data{indi} = dummy(:, indi);
49   endfor
50   resu._type(:) = class(dummy);
51   
52 endfunction