-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathopInverse.m
70 lines (56 loc) · 2.04 KB
/
opInverse.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
%opInverse (Pseudo) inverse of operator
%
% Ainv = opInverse(A) creates the (pseudo) inverse of a M-by-N
% operator A. The product Ainv*b is then equivalent to A\b.
%
% See also @opSpot/mldivide.
% Copyright 2009, Ewout van den Berg and Michael P. Friedlander
% http://www.cs.ubc.ca/labs/scl/sparco
% $Id$
classdef opInverse < opSpot
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Methods
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
methods
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Constructor
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function op = opInverse(A)
if nargin ~= 1
error('Exactly one operator must be specified.')
end
% Input matrices are immediately cast as opMatrix's.
if isa(A,'numeric'), A = opMatrix(A); end
% Check that the input operators are valid.
if ~isa(A,'opSpot')
error('Input operator is not valid.')
end
% Construct operator
[m, n] = size(A);
op = op@opSpot('Inverse', n, m);
op.cflag = A.cflag;
op.linear = A.linear;
op.children = {A};
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Display
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function str = char(op)
str = ['inv(', char(op.children{1}) ,')'];
end
end % Methods
methods ( Access = protected )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Multiply
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function y = multiply(op,x,mode)
opA = op.children{1};
if mode == 1
A = opA;
else
A = opA';
end
y = A\x;
end % Multiply
end % Methods
end % Classdef