Mercurial > octave-nkf
comparison src/DLD-FUNCTIONS/chol.cc @ 5340:15843d76156d
[project @ 2005-05-06 16:26:58 by jwe]
author | jwe |
---|---|
date | Fri, 06 May 2005 16:26:59 +0000 |
parents | 4c8a2e4e0717 |
children | be0bd7a760c9 |
comparison
equal
deleted
inserted
replaced
5339:4266ef7972b2 | 5340:15843d76156d |
---|---|
49 \n\ | 49 \n\ |
50 @example\n\ | 50 @example\n\ |
51 r' * r = a.\n\ | 51 r' * r = a.\n\ |
52 @end example\n\ | 52 @end example\n\ |
53 @end ifinfo\n\ | 53 @end ifinfo\n\ |
54 @seealso{cholinv, chol2inv}\n\ | |
54 @end deftypefn") | 55 @end deftypefn") |
55 { | 56 { |
56 octave_value_list retval; | 57 octave_value_list retval; |
57 | 58 |
58 int nargin = args.length (); | 59 int nargin = args.length (); |
111 } | 112 } |
112 else | 113 else |
113 { | 114 { |
114 gripe_wrong_type_arg ("chol", arg); | 115 gripe_wrong_type_arg ("chol", arg); |
115 } | 116 } |
117 | |
118 return retval; | |
119 } | |
120 | |
121 DEFUN_DLD (cholinv, args, nargout, | |
122 "-*- texinfo -*-\n\ | |
123 @deftypefn {Loadable Function} {} cholinv (@var{a})\n\ | |
124 Use the Cholesky factorization to compute the inverse of of the\n\ | |
125 symmetric positive definite matrix @var{a}.\n\ | |
126 @seealso{chol, chol2inv}\n\ | |
127 @end deftypefn") | |
128 { | |
129 octave_value retval; | |
130 | |
131 int nargin = args.length (); | |
132 | |
133 if (nargin == 1) | |
134 { | |
135 octave_value arg = args(0); | |
136 | |
137 octave_idx_type nr = arg.rows (); | |
138 octave_idx_type nc = arg.columns (); | |
139 | |
140 if (nr == 0 || nc == 0) | |
141 retval = Matrix (); | |
142 else | |
143 { | |
144 if (arg.is_real_type ()) | |
145 { | |
146 Matrix m = arg.matrix_value (); | |
147 | |
148 if (! error_state) | |
149 { | |
150 octave_idx_type info; | |
151 CHOL chol (m, info); | |
152 if (info == 0) | |
153 retval = chol.inverse (); | |
154 else | |
155 error ("cholinv: matrix not positive definite"); | |
156 } | |
157 } | |
158 else if (arg.is_complex_type ()) | |
159 { | |
160 ComplexMatrix m = arg.complex_matrix_value (); | |
161 | |
162 if (! error_state) | |
163 { | |
164 octave_idx_type info; | |
165 ComplexCHOL chol (m, info); | |
166 if (info == 0) | |
167 retval = chol.inverse (); | |
168 else | |
169 error ("cholinv: matrix not positive definite"); | |
170 } | |
171 } | |
172 else | |
173 gripe_wrong_type_arg ("chol", arg); | |
174 } | |
175 } | |
176 else | |
177 print_usage ("chol"); | |
178 | |
179 return retval; | |
180 } | |
181 | |
182 DEFUN_DLD (chol2inv, args, nargout, | |
183 "-*- texinfo -*-\n\ | |
184 @deftypefn {Loadable Function} {} chol2inv (@var{r})\n\ | |
185 Invert a symmetric, positive definite square matrix from its Cholesky\n\ | |
186 decomposition, @var{r}. Note that no check is performed to ensure\n\ | |
187 that @var{r} is actually a Cholesky factor.\n\ | |
188 @seealso{chol, cholinv}\n\ | |
189 @end deftypefn") | |
190 { | |
191 octave_value retval; | |
192 | |
193 int nargin = args.length (); | |
194 | |
195 if (nargin == 1) | |
196 { | |
197 octave_value arg = args(0); | |
198 | |
199 octave_idx_type nr = arg.rows (); | |
200 octave_idx_type nc = arg.columns (); | |
201 | |
202 if (nr == 0 || nc == 0) | |
203 retval = Matrix (); | |
204 else | |
205 { | |
206 if (arg.is_real_type ()) | |
207 { | |
208 Matrix r = arg.matrix_value (); | |
209 | |
210 if (! error_state) | |
211 retval = chol2inv (r); | |
212 } | |
213 else if (arg.is_complex_type ()) | |
214 { | |
215 ComplexMatrix r = arg.complex_matrix_value (); | |
216 | |
217 if (! error_state) | |
218 retval = chol2inv (r); | |
219 } | |
220 else | |
221 gripe_wrong_type_arg ("chol2inv", arg); | |
222 } | |
223 } | |
224 else | |
225 print_usage ("chol2inv"); | |
116 | 226 |
117 return retval; | 227 return retval; |
118 } | 228 } |
119 | 229 |
120 /* | 230 /* |