annotate scripts/control/base/dre.m @ 7016:93c65f2a5668

[project @ 2007-10-12 06:40:56 by jwe]
author jwe
date Fri, 12 Oct 2007 06:41:26 +0000
parents 34f96dd5441b
children a1dbe9d80eee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 1998 Auburn University. All rights reserved.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
2 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
4 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
6 ## under the terms of the GNU General Public License as published by
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## your option) any later version.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
9 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
13 ## General Public License for more details.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
14 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
17 ## <http://www.gnu.org/licenses/>.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
18
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
20 ## @deftypefn {Function File} {[@var{tvals}, @var{plist}] =} dre (@var{sys}, @var{q}, @var{r}, @var{qf}, @var{t0}, @var{tf}, @var{ptol}, @var{maxits})
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
21 ## Solve the differential Riccati equation
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
22 ## @ifinfo
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
23 ## @example
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
24 ## -d P/dt = A'P + P A - P B inv(R) B' P + Q
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
25 ## P(tf) = Qf
3439
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
26 ## @end example
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
27 ## @end ifinfo
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
28 ## @iftex
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
29 ## @tex
3439
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
30 ## $$ -{dP \over dt} = A^T P+PA-PBR^{-1}B^T P+Q $$
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
31 ## $$ P(t_f) = Q_f $$
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
32 ## @end tex
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
33 ## @end iftex
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
34 ## for the @acronym{LTI} system sys. Solution of
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
35 ## standard @acronym{LTI} state feedback optimization
3439
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
36 ## @ifinfo
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
37 ## @example
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
38 ## min int(t0, tf) ( x' Q x + u' R u ) dt + x(tf)' Qf x(tf)
3439
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
39 ## @end example
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
40 ## @end ifinfo
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
41 ## @iftex
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
42 ## @tex
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
43 ## $$ \min \int_{t_0}^{t_f} x^T Q x + u^T R u dt + x(t_f)^T Q_f x(t_f) $$
3439
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
44 ## @end tex
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
45 ## @end iftex
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
46 ## optimal input is
3439
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
47 ## @ifinfo
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
48 ## @example
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
49 ## u = - inv(R) B' P(t) x
3439
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
50 ## @end example
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
51 ## @end ifinfo
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
52 ## @iftex
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
53 ## @tex
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
54 ## $$ u = - R^{-1} B^T P(t) x $$
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
55 ## @end tex
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
56 ## @end iftex
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
57 ## @strong{Inputs}
3439
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
58 ## @table @var
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
59 ## @item sys
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
60 ## continuous time system data structure
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
61 ## @item q
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
62 ## state integral penalty
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
63 ## @item r
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
64 ## input integral penalty
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
65 ## @item qf
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
66 ## state terminal penalty
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
67 ## @item t0
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
68 ## @itemx tf
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
69 ## limits on the integral
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
70 ## @item ptol
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
71 ## tolerance (used to select time samples; see below); default = 0.1
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
72 ## @item maxits
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
73 ## number of refinement iterations (default=10)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
74 ## @end table
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
75 ## @strong{Outputs}
3439
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3431
diff changeset
76 ## @table @var
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
77 ## @item tvals
3502
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
78 ## time values at which @var{p}(@var{t}) is computed
b5238ac1dca9 [project @ 2000-01-31 07:40:53 by jwe]
jwe
parents: 3500
diff changeset
79 ## @item plist
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
80 ## list values of @var{p}(@var{t}); @var{plist} @{ @var{i} @}
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
81 ## is @var{p}(@var{tvals}(@var{i}))
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
82 ## @end table
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
83 ## @var{tvals} is selected so that:
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
84 ## @iftex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
85 ## @tex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
86 ## $$ \Vert plist_{i} - plist_{i-1} \Vert < ptol $$
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
87 ## @end tex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
88 ## @end iftex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
89 ## @ifinfo
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
90 ## @example
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
91 ## || Plist@{i@} - Plist@{i-1@} || < Ptol
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
92 ## @end example
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
93 ## @end ifinfo
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4787
diff changeset
94 ## for every @var{i} between 2 and length(@var{tvals}).
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
95 ## @end deftypefn
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
96
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
97 function [tvals, Plist] = dre (sys, Q, R, Qf, t0, tf, Ptol, maxits)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
98
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
99 if(nargin < 6 | nargin > 8 | nargout != 2)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5307
diff changeset
100 print_usage ();
4030
22bd65326ec1 [project @ 2002-08-09 18:58:13 by jwe]
jwe
parents: 3502
diff changeset
101 elseif(!isstruct(sys))
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
102 error("sys must be a system data structure")
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
103 elseif(is_digital(sys))
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
104 error("sys must be a continuous time system")
4030
22bd65326ec1 [project @ 2002-08-09 18:58:13 by jwe]
jwe
parents: 3502
diff changeset
105 elseif(!ismatrix(Q) | !ismatrix(R) | !ismatrix(Qf))
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
106 error("Q, R, and Qf must be matrices.");
4030
22bd65326ec1 [project @ 2002-08-09 18:58:13 by jwe]
jwe
parents: 3502
diff changeset
107 elseif(!isscalar(t0) | !isscalar(tf))
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
108 error("t0 and tf must be scalars")
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
109 elseif(t0 >= tf) error("t0=%e >= tf=%e",t0,tf);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
110 elseif(nargin == 6) Ptol = 0.1;
4030
22bd65326ec1 [project @ 2002-08-09 18:58:13 by jwe]
jwe
parents: 3502
diff changeset
111 elseif(!isscalar(Ptol)) error("Ptol must be a scalar");
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
112 elseif(Ptol <= 0) error("Ptol must be positive");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
113 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
114
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
115 if(nargin < 8) maxits = 10;
4030
22bd65326ec1 [project @ 2002-08-09 18:58:13 by jwe]
jwe
parents: 3502
diff changeset
116 elseif(!isscalar(maxits)) error("maxits must be a scalar");
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
117 elseif(maxits <= 0) error("maxits must be positive");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
118 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
119 maxits = ceil(maxits);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
120
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
121 [aa,bb] = sys2ss(sys);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
122 nn = sysdimensions(sys,"cst");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
123 mm = sysdimensions(sys,"in");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
124 pp = sysdimensions(sys,"out");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
125
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
126 if(size(Q) != [nn, nn])
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
127 error("Q(%dx%d); sys has %d states",rows(Q),columns(Q),nn);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
128 elseif(size(Qf) != [nn, nn])
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
129 error("Qf(%dx%d); sys has %d states",rows(Qf),columns(Qf),nn);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
130 elseif(size(R) != [mm, mm])
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
131 error("R(%dx%d); sys has %d inputs",rows(R),columns(R),mm);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
132 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
133
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
134 ## construct Hamiltonian matrix
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
135 H = [aa , -(bb/R)*bb' ; -Q, -aa'];
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
136
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
137 ## select time step to avoid numerical overflow
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
138 fast_eig = max(abs(eig(H)));
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
139 tc = log(10)/fast_eig;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
140 nst = ceil((tf-t0)/tc);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
141 tvals = -linspace(-tf,-t0,nst);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
142 Plist = list(Qf);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
143 In = eye(nn);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
144 n1 = nn+1;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
145 n2 = nn+nn;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
146 done = 0;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
147 while(!done)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
148 done = 1; # assume this pass will do the job
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
149 ## sort time values in reverse order
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
150 tvals = -sort(-tvals);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
151 tvlen = length(tvals);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
152 maxerr = 0;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
153 ## compute new values of P(t); recompute old values just in case
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
154 for ii=2:tvlen
4771
b8105302cfe8 [project @ 2004-02-16 17:45:50 by jwe]
jwe
parents: 4030
diff changeset
155 uv_i_minus_1 = [ In ; Plist{ii-1} ];
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
156 delta_t = tvals(ii-1) - tvals(ii);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
157 uv = expm(-H*delta_t)*uv_i_minus_1;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
158 Qi = uv(n1:n2,1:nn)/uv(1:nn,1:nn);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
159 Plist(ii) = (Qi+Qi')/2;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
160 ## check error
4771
b8105302cfe8 [project @ 2004-02-16 17:45:50 by jwe]
jwe
parents: 4030
diff changeset
161 Perr = norm(Plist{ii} - Plist{ii-1})/norm(Plist{ii});
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
162 maxerr = max(maxerr,Perr);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
163 if(Perr > Ptol)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
164 new_t = mean(tvals([ii,ii-1]));
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
165 tvals = [tvals, new_t];
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
166 done = 0;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
167 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
168 endfor
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
169
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
170 ## check number of iterations
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
171 maxits = maxits - 1;
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
172 done = done+(maxits==0);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
173 endwhile
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
174 if(maxerr > Ptol)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
175 warning("dre: \n\texiting with%4d points, max rel chg. =%e, Ptol=%e\n", ...
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
176 tvlen,maxerr,Ptol);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
177 tvals = tvals(1:length(Plist));
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
178 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
179
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
180 endfunction