Mercurial > octave
annotate scripts/plot/draw/stream2.m @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
1 ## Copyright (C) 2019-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27810
diff
changeset
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27810
diff
changeset
|
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27810
diff
changeset
|
4 ## or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27810
diff
changeset
|
5 ## |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
6 ## |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
7 ## This file is part of Octave. |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
8 ## |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
9 ## Octave is free software: you can redistribute it and/or modify it |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
10 ## under the terms of the GNU General Public License as published by |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
11 ## the Free Software Foundation, either version 3 of the License, or |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
12 ## (at your option) any later version. |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
13 ## |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
14 ## Octave is distributed in the hope that it will be useful, but |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
17 ## GNU General Public License for more details. |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
18 ## |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
19 ## You should have received a copy of the GNU General Public License |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
20 ## along with Octave; see the file COPYING. If not, see |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
21 ## <https://www.gnu.org/licenses/>. |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
22 |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
23 ## -*- texinfo -*- |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
24 ## @deftypefn {} {@var{xy} =} stream2 (@var{x}, @var{y}, @var{u}, @var{v}, @var{sx}, @var{sy}) |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
25 ## @deftypefnx {} {@var{xy} =} stream2 (@var{u}, @var{v}, @var{sx}, @var{sy}) |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
26 ## @deftypefnx {} {@var{xy} =} stream2 (@dots{}, @var{options}) |
27794
45ad2127582b
doc: grammarcheck scripts before 6.1 release.
Rik <rik@octave.org>
parents:
27759
diff
changeset
|
27 ## Compute 2-D streamline data. |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
28 ## |
27794
45ad2127582b
doc: grammarcheck scripts before 6.1 release.
Rik <rik@octave.org>
parents:
27759
diff
changeset
|
29 ## Calculates streamlines of a vector field given by @code{[@var{u}, @var{v}]}. |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
30 ## The vector field is defined over a rectangular grid given by |
27794
45ad2127582b
doc: grammarcheck scripts before 6.1 release.
Rik <rik@octave.org>
parents:
27759
diff
changeset
|
31 ## @code{[@var{x}, @var{y}]}. The streamlines start at the seed points |
45ad2127582b
doc: grammarcheck scripts before 6.1 release.
Rik <rik@octave.org>
parents:
27759
diff
changeset
|
32 ## @code{[@var{sx}, @var{sy}]}. The returned value @var{xy} contains a cell |
45ad2127582b
doc: grammarcheck scripts before 6.1 release.
Rik <rik@octave.org>
parents:
27759
diff
changeset
|
33 ## array of vertex arrays. If the starting point is outside the vector field, |
45ad2127582b
doc: grammarcheck scripts before 6.1 release.
Rik <rik@octave.org>
parents:
27759
diff
changeset
|
34 ## @code{[]} is returned. |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
35 ## |
27794
45ad2127582b
doc: grammarcheck scripts before 6.1 release.
Rik <rik@octave.org>
parents:
27759
diff
changeset
|
36 ## The input parameter @var{options} is a 2-D vector of the form |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
37 ## @code{[@var{stepsize}, @var{max_vertices}]}. The first parameter |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
38 ## specifies the step size used for trajectory integration (default 0.1). A |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
39 ## negative value is allowed which will reverse the direction of integration. |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
40 ## The second parameter specifies the maximum number of segments used to |
27794
45ad2127582b
doc: grammarcheck scripts before 6.1 release.
Rik <rik@octave.org>
parents:
27759
diff
changeset
|
41 ## create a streamline (default 10,000). |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
42 ## |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
43 ## The return value @var{xy} is a @nospell{nverts x 2} matrix containing the |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
44 ## coordinates of the field line segments. |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
45 ## |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
46 ## Example: |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
47 ## |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
48 ## @example |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
49 ## @group |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
50 ## [x, y] = meshgrid (0:3); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
51 ## u = 2 * x; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
52 ## v = y; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
53 ## xy = stream2 (x, y, u, v, 1.0, 0.5); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
54 ## @end group |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
55 ## @end example |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
56 ## |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
57 ## @seealso{streamline, stream3} |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
58 ## @end deftypefn |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
59 |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
60 ## References: |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
61 ## |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
62 ## @article{ |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
63 ## title = {Particle Tracing Algorithms for 3D Curvilinear Grids}, |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
64 ## year = {2000}, |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
65 ## author = {Nielson, Gregory and Uller, H. and Sadarjoen, I. and Walsum, Theo and Hin, Andrea and Post, Frits} |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
66 ## } |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
67 ## |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
68 ## @article{ |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
69 ## title = {Sources of error in the graphical analysis of CFD results}, |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
70 ## publisher = {Journal of Scientific Computing}, |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
71 ## year = {1988}, |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
72 ## volume = {3}, |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
73 ## number = {2}, |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
74 ## pages = {149--164}, |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
75 ## author = {Buning, Pieter G.}, |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
76 ## } |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
77 |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
78 function xy = stream2 (varargin) |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
79 |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
80 options = []; |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
81 switch (numel (varargin)) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
82 case 0 |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
83 print_usage (); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
84 case {4,5} |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
85 if (numel (varargin) == 4) |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
86 [u, v, spx, spy] = varargin{:}; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
87 else |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
88 [u, v, spx, spy, options] = varargin{:}; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
89 endif |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
90 [m, n] = size (u); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
91 [x, y] = meshgrid (1:n, 1:m); |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
92 case 6 |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
93 [x, y, u, v, spx, spy] = varargin{:}; |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
94 case 7 |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
95 [x, y, u, v, spx, spy, options] = varargin{:}; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
96 otherwise |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
97 error ("stream2: invalid number of inputs"); |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
98 endswitch |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
99 |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
100 stepsize = 0.1; |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
101 max_vertices = 10_000; |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
102 if (! isempty (options)) |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
103 switch (numel (options)) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
104 case 1 |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
105 stepsize = options(1); |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
106 case 2 |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
107 stepsize = options(1); |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
108 max_vertices = options(2); |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
109 otherwise |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
110 error ("stream2: invalid number of OPTIONS elements"); |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
111 endswitch |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
112 |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
113 if (! isreal (stepsize) || stepsize == 0) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
114 error ("stream2: STEPSIZE must be a real scalar != 0"); |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
115 endif |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
116 if (! isreal (max_vertices) || max_vertices < 1) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
117 error ("stream2: MAX_VERTICES must be an integer > 0"); |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
118 endif |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
119 max_vertices = fix (max_vertices); |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
120 endif |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
121 |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
122 if (! (size_equal (u, v, x, y) && size_equal (spx, spy))) |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
123 error ("stream2: matrix dimensions must match"); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
124 endif |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
125 if (iscomplex (u) || iscomplex (v) || iscomplex (x) || iscomplex (y) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
126 || iscomplex (spx) || iscomplex (spy)) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
127 error ("stream2: all inputs must be real-valued"); |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
128 endif |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
129 |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
130 gx = x(1,:); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
131 gy = y(:,1).'; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
132 |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
133 ## Jacobian Matrix |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
134 dx = diff (gx); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
135 dy = diff (gy); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
136 ## "<" used to check if the mesh is ascending |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
137 if (any (dx <= 0) || any (dy <= 0) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
138 || any (isnan (dx)) || any (isnan (dy))) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
139 error ("stream2: non-monotonically increasing or NaN values found in mesh"); |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
140 endif |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
141 tx = 1 ./ dx; |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
142 ty = 1 ./ dy; |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
143 ## "Don't cares" used for handling points located on the border |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
144 tx(end + 1) = 0; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
145 ty(end + 1) = 0; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
146 dx(end + 1) = 0; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
147 dy(end + 1) = 0; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
148 |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
149 px = spx(:); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
150 py = spy(:); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
151 |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
152 for nseed = 1 : numel (px) |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
153 |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
154 xp = px(nseed); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
155 yp = py(nseed); |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
156 idx = find (diff (gx <= xp), 1); |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
157 if (gx(end) == xp) |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
158 idx = numel (gx); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
159 endif |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
160 idy = find (diff (gy <= yp), 1); |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
161 if (gy(end) == yp) |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
162 idy = numel (gy); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
163 endif |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
164 |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
165 if (isempty (idx) || isempty (idy)) |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
166 xy{nseed} = []; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
167 else |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
168 ## Transform seed from P coordinates to C coordinates |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
169 zeta = (idx - 1) + (xp - gx(idx)) * tx(idx); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
170 xi = (idy - 1) + (yp - gy(idy)) * ty(idy); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
171 |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
172 C = __streameuler2d__ (u, v, tx, ty, zeta, xi, stepsize, max_vertices); |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
173 |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
174 ## Transform from C coordinates to P coordinates |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
175 idu = floor (C(:,1)); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
176 idv = floor (C(:,2)); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
177 xy{nseed} = [gx(idu + 1).' + (C(:,1) - idu).*(dx(idu + 1).'), ... |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
178 gy(idv + 1).' + (C(:,2) - idv).*(dy(idv + 1).')]; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
179 endif |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
180 |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
181 endfor |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
182 |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
183 endfunction |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
184 |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
185 |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
186 %!demo |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
187 %! clf; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
188 %! [x, y] = meshgrid (-5:5, -4:4); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
189 %! u = x - 2 * y; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
190 %! v = 2 * x - 3 * y; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
191 %! sx = [3, 0, -1, -2, -3, 0, 1, 2]; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
192 %! sy = [3, 3, 3, 3, -3, -3, -3, -3]; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
193 %! h = streamline (x, y, u, v, sx, sy, 0.05); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
194 %! set (h, "color", "r"); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
195 %! hold on; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
196 %! quiver (x, y, u, v); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
197 %! scatter (sx(:), sy(:), 20, "filled", "o", "markerfacecolor", "r"); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
198 %! grid on; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
199 %! title ("Asymptotically Stable Equilibrium"); |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
200 %! axis equal; |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
201 |
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
202 %!test |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
203 %! xy = stream2 ([1,1,1;2,2,2;3,3,3], [1,1,1;2,2,2;3,3,3], 1, 1, [0.01,5]); |
27759
992e702ef0d7
Add stream* functions (patch #9859).
Markus Meisinger <chloros2@gmx.de>
parents:
diff
changeset
|
204 %! assert (numel (xy{:}), 10); |
27810
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
205 |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
206 ## Test input validation |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
207 %!error stream2 () |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
208 %!error <invalid number of inputs> stream2 (1) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
209 %!error <invalid number of inputs> stream2 (1,2) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
210 %!error <invalid number of inputs> stream2 (1,2,3) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
211 %!error <invalid number of OPTIONS> stream2 (1,2,3,4, [1,2,3]) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
212 %!error <STEPSIZE must be a real scalar != 0> stream2 (1,2,3,4, [1i]) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
213 %!error <STEPSIZE must be a real scalar != 0> stream2 (1,2,3,4, [0]) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
214 %!error <MAX_VERTICES must be an integer> stream2 (1,2,3,4, [1, 1i]) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
215 %!error <MAX_VERTICES must be an integer> stream2 (1,2,3,4, [1, 0]) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
216 %!error <matrix dimensions must match> stream2 ([1 1],2,3,4) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
217 %!error <matrix dimensions must match> stream2 (1,[2 2],3,4) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
218 %!error <matrix dimensions must match> stream2 (1,2,[3 3],4) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
219 %!error <matrix dimensions must match> stream2 (1,2,3,[4 4]) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
220 %!error <all inputs must be real-valued> stream2 (1i,2,3,4) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
221 %!error <all inputs must be real-valued> stream2 (1,2i,3,4) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
222 %!error <all inputs must be real-valued> stream2 (1,2,3i,4) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
223 %!error <all inputs must be real-valued> stream2 (1,2,3,4i) |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
224 %!error <non-monotonically increasing or NaN values found in mesh> |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
225 %! stream2 ([2 1], [1 2], [1 1], [2 2], [3 3], [4 4]); |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
226 %!error <non-monotonically increasing or NaN values found in mesh> |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
227 %! stream2 ([1 NaN], [1 2], [1 1], [2 2], [3 3], [4 4]); |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
228 ## FIXME: vectors representing x, y mesh are not accepted. |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
229 %#!error <non-monotonically increasing or NaN values found in mesh> |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
230 %! stream2 ([1 2], [2 1], [1 1], [2 2], [3 3], [4 4]); |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
231 %#!error <non-monotonically increasing or NaN values found in mesh> |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
232 %! stream2 ([1 2], [1 NaN], [1 1], [2 2], [3 3], [4 4]); |
f2b89a2e20b6
overhaul streamXXX.m series of functions.
Rik <rik@octave.org>
parents:
27808
diff
changeset
|
233 |