annotate scripts/control/base/nyquist.m @ 7126:4a375de63f66

[project @ 2007-11-08 03:44:14 by jwe]
author jwe
date Thu, 08 Nov 2007 03:44:15 +0000
parents a1dbe9d80eee
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
1 ## Copyright (C) 1996, 1998, 2000, 2003, 2004, 2005, 2006, 2007
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
2 ## Auburn University. All rights reserved.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
3 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
4 ## This file is part of Octave.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
5 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
6 ## 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: 6448
diff changeset
7 ## under the terms of the GNU General Public License as published by
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6448
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6448
diff changeset
9 ## your option) any later version.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
10 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6448
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6448
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6448
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6448
diff changeset
14 ## General Public License for more details.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
15 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
16 ## 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: 6448
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6448
diff changeset
18 ## <http://www.gnu.org/licenses/>.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
19
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
20 ## -*- texinfo -*-
3500
7923abdeb4e5 [project @ 2000-01-31 06:35:00 by jwe]
jwe
parents: 3462
diff changeset
21 ## @deftypefn {Function File} {[@var{realp}, @var{imagp}, @var{w}] =} nyquist (@var{sys}, @var{w}, @var{out_idx}, @var{in_idx}, @var{atol})
7923abdeb4e5 [project @ 2000-01-31 06:35:00 by jwe]
jwe
parents: 3462
diff changeset
22 ## @deftypefnx {Function File} {} nyquist (@var{sys}, @var{w}, @var{out_idx}, @var{in_idx}, @var{atol})
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
23 ## Produce Nyquist plots of a system; if no output arguments are given, Nyquist
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
24 ## plot is printed to the screen.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
25 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
26 ## Compute the frequency response of a system.
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
27 ##
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
28 ## @strong{Inputs} (pass as empty to get default values)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
29 ## @table @var
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
30 ## @item sys
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
31 ## system data structure (must be either purely continuous or discrete;
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
32 ## see @code{is_digital})
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
33 ## @item w
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
34 ## frequency values for evaluation.
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
35 ## If sys is continuous, then bode evaluates @math{G(@var{jw})};
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
36 ## if sys is discrete, then bode evaluates @math{G(exp(@var{jwT}))},
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
37 ## where @var{T} is the system sampling time.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
38 ## @item default
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
39 ## the default frequency range is selected as follows: (These
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
40 ## steps are @strong{not} performed if @var{w} is specified)
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
41 ## @enumerate
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
42 ## @item via routine @command{__bodquist__}, isolate all poles and zeros away from
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
43 ## @var{w}=0 (@var{jw}=0 or @math{exp(@var{jwT})=1}) and select the frequency
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
44 ## range based on the breakpoint locations of the frequencies.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
45 ## @item if @var{sys} is discrete time, the frequency range is limited
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
46 ## to @var{jwT} in
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
47 ## @ifinfo
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
48 ## [0,2p*pi]
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
49 ## @end ifinfo
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
50 ## @iftex
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
51 ## @tex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
52 ## $ [ 0,2 p \pi ] $
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
53 ## @end tex
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
54 ## @end iftex
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
55 ## @item A ``smoothing'' routine is used to ensure that the plot phase does
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
56 ## not change excessively from point to point and that singular
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
57 ## points (e.g., crossovers from +/- 180) are accurately shown.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
58 ## @end enumerate
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
59 ## @item atol
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
60 ## for interactive nyquist plots: atol is a change-in-slope tolerance
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
61 ## for the of asymptotes (default = 0; 1e-2 is a good choice). This allows
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
62 ## the user to ``zoom in'' on portions of the Nyquist plot too small to be
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
63 ## seen with large asymptotes.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
64 ## @end table
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
65 ## @strong{Outputs}
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
66 ## @table @var
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
67 ## @item realp
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
68 ## @itemx imagp
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
69 ## the real and imaginary parts of the frequency response
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
70 ## @math{G(jw)} or @math{G(exp(jwT))} at the selected frequency values.
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
71 ## @item w
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
72 ## the vector of frequency values used
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
73 ## @end table
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
74 ##
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
75 ## If no output arguments are given, nyquist plots the results to the screen.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
76 ## If @var{atol} != 0 and asymptotes are detected then the user is asked
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
77 ## interactively if they wish to zoom in (remove asymptotes)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
78 ## Descriptive labels are automatically placed.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
79 ##
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
80 ## Note: if the requested plot is for an @acronym{MIMO} system, a warning message is
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
81 ## presented; the returned information is of the magnitude
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
82 ## @iftex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
83 ## @tex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
84 ## $ \Vert G(jw) \Vert $ or $ \Vert G( {\rm exp}(jwT) \Vert $
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
85 ## @end tex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
86 ## @end iftex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
87 ## @ifinfo
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
88 ## ||G(jw)|| or ||G(exp(jwT))||
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
89 ## @end ifinfo
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4771
diff changeset
90 ## only; phase information is not computed.
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
91 ## @end deftypefn
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
92
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
93 ## Author: R. Bruce Tenison <btenison@eng.auburn.edu>
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
94 ## Created: July 13, 1994
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
95 ## A. S. Hodel July 1995 (adaptive frequency spacing,
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
96 ## remove acura parameter, etc.)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
97 ## Revised by John Ingram July 1996 for system format
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 function [realp, imagp, w] = nyquist (sys, w, outputs, inputs, atol)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
100
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
101 ## Both bode and nyquist share the same introduction, so the common
3438
2e06c3941943 [project @ 2000-01-14 06:33:18 by jwe]
jwe
parents: 3431
diff changeset
102 ## parts are in a file called __bodquist__.m. It contains the part that
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
103 ## finds the number of arguments, determines whether or not the system
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
104 ## is SISO, andd computes the frequency response. Only the way the
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
105 ## response is plotted is different between the two functions.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
106
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
107 ## check number of input arguments given
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
108 if (nargin < 1 || nargin > 5)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 6024
diff changeset
109 print_usage ();
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
110 endif
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
111 if (nargin < 2)
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
112 w = [];
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
113 endif
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
114 if (nargin < 3)
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
115 outputs = [];
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
116 endif
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
117 if (nargin < 4)
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
118 inputs = [];
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
119 endif
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
120 if (nargin < 5)
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
121 atol = 0;
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
122 elseif (! (is_sample (atol) || atol == 0))
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
123 error ("nyquist: atol must be a nonnegative scalar")
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
124 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
125
3438
2e06c3941943 [project @ 2000-01-14 06:33:18 by jwe]
jwe
parents: 3431
diff changeset
126 ## signal to __bodquist__ who's calling
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
127
3455
f758be6e1730 [project @ 2000-01-18 19:57:12 by hodelas]
hodelas
parents: 3438
diff changeset
128 [f, w, sys] = __bodquist__ (sys, w, outputs, inputs, "nyquist");
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
129
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
130 ## Get the real and imaginary part of f.
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
131 realp = real (f);
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
132 imagp = imag (f);
3431
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 ## No output arguments, then display plot, otherwise return data.
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
135 if (nargout == 0)
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
136 dnplot = 0;
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
137 while (! dnplot)
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
138 plot (realp, imagp, "- ;+w;", realp, -imagp, "-@ ;-w;");
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
139
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
140 grid ("on");
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
141
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
142 if (is_digital (sys))
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
143 tstr = " G(e^{jw}) ";
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
144 else
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
145 tstr = " G(jw) ";
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
146 endif
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
147 xlabel (sprintf ("Re(%s)", tstr));
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
148 ylabel (sprintf ("Im(%s)", tstr));
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
149
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
150 [stn, inn, outn] = sysgetsignals (sys);
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
151 if (is_siso (sys))
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
152 title (sprintf ("Nyquist plot from %s to %s, w (rad/s) in [%e, %e]",
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
153 inn{1}, outn{1}, w(1), w(end)));
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
154 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
155
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
156 axis (axis2dlim ([[realp(:), imagp(:)]; [realp(:), -imagp(:)]]));
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
157
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
158 ## check for interactive plots
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
159 dnplot = 1; # assume done; will change later if atol is satisfied
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
160 if (atol > 0 && length (f) > 2)
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
161
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
162 ## check for asymptotes
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
163 fmax = max (abs (f));
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
164 fi = find (abs (f) == fmax, 1, "last");
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
165
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
166 ## compute angles from point to point
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
167 df = diff (f);
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
168 th = atan2 (real (df), imag (df)) * 180 / pi;
3431
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 ## get angle at fmax
7126
4a375de63f66 [project @ 2007-11-08 03:44:14 by jwe]
jwe
parents: 7017
diff changeset
171 if (fi == length (f))
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
172 fi = fi-1;
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
173 endif
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
174 thm = th(fi);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
175
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
176 ## now locate consecutive angles within atol of thm
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
177 ith_same = find (abs (th - thm) < atol);
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
178 ichk = union (fi, find (diff (ith_same) == 1));
3431
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 ## locate max, min consecutive indices in ichk
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
181 loval = max (complement (ichk, 1:fi));
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
182 if (isempty (loval))
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
183 loval = fi;
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
184 else
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
185 loval = loval + 1;
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
186 endif
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
187
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
188 hival = min (complement (ichk, fi:length(th)));
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
189 if (isempty (hival))
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
190 hival = fi+1;
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
191 endif
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
192
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
193 keep_idx = complement (loval:hival, 1:length(w));
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
194
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
195 if (length (keep_idx))
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
196 resp = input ("Remove asymptotes and zoom in (y or n): ", 1);
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
197 if (resp(1) == "y")
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
198 dnplot = 0; # plot again
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
199 w = w(keep_idx);
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
200 f = f(keep_idx);
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
201 realp = real (f);
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
202 imagp = imag (f);
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
203 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
204 endif
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
205
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
206 endif
6448
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
207 endwhile
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
208 w = realp = imagp = [];
2110cc251779 [project @ 2007-03-24 02:47:36 by jwe]
jwe
parents: 6046
diff changeset
209 endif
3431
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
210
99ab64f4a09d [project @ 2000-01-14 03:53:03 by jwe]
jwe
parents:
diff changeset
211 endfunction