Mercurial > octave-nkf
annotate doc/interpreter/sparseimages.m @ 20351:d8992a16643c
doc: Clean up m-files which generate images for Manual.
* geometryimages.m, interpimages.m, plotimages.m, sparseimages.m,
splineimages.m: Use the same style throughout the mi-files.
Obey Octave coding conventions.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 09 Jul 2015 21:38:57 -0700 |
parents | c3c1fb44f9b5 |
children | b439ccc9a162 |
rev | line source |
---|---|
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19627
diff
changeset
|
1 ## Copyright (C) 2006-2015 David Bateman |
7018 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
19 function sparseimages (d, nm, typ) |
19751
606b05352351
Backout cset 59ad278cfb98, use gnuplot for building doc images.
Rik <rik@octave.org>
parents:
19742
diff
changeset
|
20 graphics_toolkit ("gnuplot"); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
21 set_print_size (); |
7257 | 22 if (strcmp (typ, "png")) |
23 set (0, "defaulttextfontname", "*"); | |
24 endif | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
25 |
16170
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
26 if (__have_feature__ ("COLAMD") |
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
27 && __have_feature__ ("CHOLMOD") |
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
28 && __have_feature__ ("UMFPACK")) |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
29 if (strcmp (typ,"txt")) |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
30 txtimages (d, nm, 15, typ); |
6003 | 31 else |
6126 | 32 if (strcmp (nm, "gplot")) |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
33 gplotimages (d, "gplot", typ); |
6126 | 34 elseif (strcmp (nm, "grid")) |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
35 femimages (d, "grid", typ); |
6126 | 36 else |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
37 otherimages (d, nm, 200, typ); |
6126 | 38 endif |
6003 | 39 endif |
6040 | 40 else ## There is no sparse matrix implementation available because |
41 ## of missing libraries, plot sombreros instead | |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
42 sombreroimage (d, nm, typ); |
6040 | 43 endif |
6003 | 44 endfunction |
45 | |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
46 function gplotimages (d, nm, typ) |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
47 hide_output (); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
48 outfile = fullfile (d, strcat (nm, ".", typ)); |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
49 if (strcmp (typ, "eps")) |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
50 d_typ = "-depsc2"; |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
51 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
52 d_typ = ["-d" typ]; |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
53 endif |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
54 |
6040 | 55 A = sparse ([2,6,1,3,2,4,3,5,4,6,1,5], |
11033
d9c8916bb9dd
Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents:
9914
diff
changeset
|
56 [1,1,2,2,3,3,4,4,5,5,6,6], 1, 6, 6); |
6003 | 57 xy = [0,4,8,6,4,2;5,0,5,7,5,7]'; |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
58 gplot (A, xy); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
59 print (outfile, d_typ); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
60 hide_output (); |
6003 | 61 endfunction |
62 | |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
63 function txtimages (d, nm, n, typ) |
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
64 outfile = fullfile (d, strcat (nm, ".", typ)); |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
65 a = 10*speye (n) + sparse (1:n,ceil([1:n]/2),1,n,n) + ... |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
66 sparse (ceil ([1:n]/2),1:n,1,n,n); |
6003 | 67 if (strcmp (nm, "gplot") || strcmp (nm, "grid")) |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
68 fid = fopen (fullfile (d, strcat (nm, ".txt")), "wt"); |
7256 | 69 fputs (fid, "\n"); |
6003 | 70 fputs (fid, "+---------------------------------+\n"); |
71 fputs (fid, "| Image unavailable in text mode. |\n"); | |
72 fputs (fid, "+---------------------------------+\n"); | |
73 fclose (fid); | |
74 elseif (strcmp (nm, "spmatrix")) | |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
75 printsparse (a, outfile); |
6003 | 76 else |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
77 if (__have_feature__ ("COLAMD") && __have_feature__ ("CHOLMOD")) |
6003 | 78 if (strcmp (nm, "spchol")) |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
79 r1 = chol (a); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
80 printsparse (r1, outfile); |
6003 | 81 elseif (strcmp (nm, "spcholperm")) |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
82 [r2,p2,q2] = chol (a); |
20351
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
83 printsparse (r2, outfile); |
6003 | 84 endif |
85 ## printf("Text NNZ: Matrix %d, Chol %d, PermChol %d\n",nnz(a),nnz(r1),nnz(r2)); | |
86 endif | |
87 endif | |
88 endfunction | |
89 | |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
90 function otherimages (d, nm, n, typ) |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
91 hide_output (); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
92 outfile = fullfile (d, strcat (nm, ".", typ)); |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
93 if (strcmp (typ, "eps")) |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
94 d_typ = "-depsc2"; |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
95 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
96 d_typ = ["-d" typ]; |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
97 endif |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
98 |
20351
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
99 a = 10*speye (n) + sparse (1:n,ceil ([1:n]/2),1,n,n) + ... |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
100 sparse (ceil ([1:n]/2),1:n,1,n,n); |
6003 | 101 if (strcmp (nm, "spmatrix")) |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
102 spy (a); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
103 axis ("ij"); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
104 print (outfile, d_typ); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
105 hide_output (); |
6003 | 106 else |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
107 if (__have_feature__ ("COLAMD") && __have_feature__ ("CHOLMOD")) |
6003 | 108 if (strcmp (nm, "spchol")) |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
109 r1 = chol (a); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
110 spy (r1); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
111 axis ("ij"); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
112 print (outfile, d_typ); |
11033
d9c8916bb9dd
Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents:
9914
diff
changeset
|
113 hide_output (); |
6003 | 114 elseif (strcmp (nm, "spcholperm")) |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
115 [r2,p2,q2] = chol (a); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
116 spy (r2); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
117 axis ("ij"); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
118 print (outfile, d_typ); |
11033
d9c8916bb9dd
Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents:
9914
diff
changeset
|
119 hide_output (); |
6003 | 120 endif |
121 ## printf("Image NNZ: Matrix %d, Chol %d, PermChol %d\n",nnz(a),nnz(r1),nnz(r2)); | |
122 endif | |
123 endif | |
124 endfunction | |
125 | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
126 function printsparse (a, nm) |
6003 | 127 fid = fopen (nm,"wt"); |
7256 | 128 fputs (fid, "\n"); |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
129 for i = 1:rows (a) |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
130 if (rem (i,5) == 0) |
6003 | 131 fprintf (fid," %2d - ", i); |
132 else | |
133 fprintf (fid," | "); | |
134 endif | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
135 for j = 1:columns (a) |
6003 | 136 if (a(i,j) == 0) |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
137 fprintf (fid," "); |
6003 | 138 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
139 fprintf (fid," *"); |
6003 | 140 endif |
141 endfor | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
142 fprintf (fid,"\n"); |
6003 | 143 endfor |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
144 fprintf (fid," |-"); |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
145 for j = 1:columns (a) |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
146 if (rem (j,5) == 0) |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
147 fprintf (fid,"-|"); |
6003 | 148 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
149 fprintf (fid,"--"); |
6003 | 150 endif |
151 endfor | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
152 fprintf (fid,"\n"); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
153 fprintf (fid," "); |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
154 for j = 1:columns (a) |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
155 if (rem (j,5) == 0) |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
156 fprintf (fid,"%2d",j); |
6003 | 157 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
158 fprintf (fid," "); |
6003 | 159 endif |
160 endfor | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
161 fclose (fid); |
6003 | 162 endfunction |
163 | |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
164 function femimages (d, nm, typ) |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
165 hide_output (); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
166 outfile = fullfile (d, strcat (nm, ".", typ)); |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
167 if (strcmp (typ, "eps")) |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
168 d_typ = "-depsc2"; |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
169 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
170 d_typ = ["-d" typ]; |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
171 endif |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
172 |
16170
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
173 if (__have_feature__ ("COLAMD") |
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
174 && __have_feature__ ("CHOLMOD") |
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
175 && __have_feature__ ("UMFPACK")) |
6003 | 176 ## build a rectangle |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
177 node_y = [1;1.2;1.5;1.8;2] * ones (1,11); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
178 node_x = ones (5,1) * [1,1.05,1.1,1.2,1.3,1.5,1.7,1.8,1.9,1.95,2]; |
6003 | 179 nodes = [node_x(:), node_y(:)]; |
180 | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
181 [h,w] = size (node_x); |
6003 | 182 elems = []; |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
183 for idx = 1 : w-1 |
6003 | 184 widx = (idx-1)*h; |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17887
diff
changeset
|
185 elems = [elems; widx+[(1:h-1);(2:h);h+(1:h-1)]']; |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17887
diff
changeset
|
186 elems = [elems; widx+[(2:h);h+(2:h);h+(1:h-1)]']; |
6003 | 187 endfor |
188 | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
189 E = size (elems,1); # No. of elements |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
190 N = size (nodes,1); # No. of elements |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
191 D = size (elems,2); # dimensions+1 |
6003 | 192 |
193 ## Plot FEM Geometry | |
194 elemx = elems(:,[1,2,3,1])'; | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
195 xelems = reshape (nodes(elemx, 1), 4, E); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
196 yelems = reshape (nodes(elemx, 2), 4, E); |
6003 | 197 |
198 ## Set element conductivity | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
199 conductivity = [1*ones(1,16), 2*ones(1,48), 1*ones(1,16)]; |
6003 | 200 |
201 ## Dirichlet boundary conditions | |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17887
diff
changeset
|
202 D_nodes = [1:5, 51:55]; |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17887
diff
changeset
|
203 D_value = [10*ones(1,5), 20*ones(1,5)]; |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17887
diff
changeset
|
204 |
6003 | 205 ## Neumann boundary conditions |
206 ## Note that N_value must be normalized by the boundary | |
207 ## length and element conductivity | |
208 N_nodes = []; | |
209 N_value = []; | |
210 | |
211 ## Calculate connectivity matrix | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
212 C = sparse ((1:D*E), reshape (elems',D*E,1),1, D*E, N); |
6003 | 213 |
214 ## Calculate stiffness matrix | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
215 Siidx = floor ([0:D*E-1]'/D)*D*ones(1,D) + ones(D*E,1)*(1:D); |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
216 Sjidx = [1:D*E]'*ones (1,D); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
217 Sdata = zeros (D*E,D); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
218 dfact = prod (2:(D-1)); |
6003 | 219 for j = 1:E |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
220 a = inv ([ ones(D,1), nodes( elems(j,:), : ) ]); |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
221 const = conductivity(j)*2/dfact/abs (det (a)); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
222 Sdata(D*(j-1)+(1:D),:) = const * a(2:D,:)'*a(2:D,:); |
6003 | 223 endfor |
224 | |
225 ## Element-wise system matrix | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
226 SE = sparse (Siidx,Sjidx,Sdata); |
6003 | 227 ## Global system matrix |
228 S = C'* SE *C; | |
229 | |
230 ## Set Dirichlet boundary | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
231 V = zeros (N,1); |
6003 | 232 V(D_nodes) = D_value; |
233 idx = 1:N; | |
234 idx(D_nodes) = []; | |
235 | |
236 ## Set Neumann boundary | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
237 Q = zeros (N,1); |
6003 | 238 Q(N_nodes) = N_value; # FIXME |
239 | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
240 V(idx) = S(idx,idx) \ ( Q(idx) - S(idx,D_nodes)*V(D_nodes) ); |
6003 | 241 |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
242 velems = reshape (V(elemx), 4, E); |
6178 | 243 |
244 plot3 (xelems, yelems, velems); | |
17887
3252b366bb5d
sparseimages.m: Fix incorrect view() command for printed image.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
245 view (80, 10); |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
246 print (outfile, d_typ); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
247 hide_output (); |
6003 | 248 endif |
249 endfunction | |
6040 | 250 |
251 ## There is no sparse matrix implementation available because of missing | |
252 ## libraries, plot sombreros instead. Also plot a nice title that we are | |
253 ## sorry about that. | |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
254 function sombreroimage (d, nm, typ) |
6040 | 255 if (strcmp (typ, "txt")) |
20351
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
256 fid = fopen (fullfile (d, [nm ".txt"]), "wt"); |
7256 | 257 fputs (fid, "\n"); |
6040 | 258 fputs (fid, "+---------------------------------------+\n"); |
259 fputs (fid, "| Image unavailable because of a |\n"); | |
260 fputs (fid, "| missing sparse matrix implementation. |\n"); | |
261 fputs (fid, "+---------------------------------------+\n"); | |
262 fclose (fid); | |
263 return; | |
20351
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
264 else |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
265 hide_output (); |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
266 if (strcmp (typ, "eps")) |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
267 d_typ = "-depsc2"; |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
268 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
269 d_typ = ["-d" typ]; |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
270 endif |
6040 | 271 |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
272 [x, y, z] = sombrero (); |
6040 | 273 unwind_protect |
6257 | 274 mesh (x, y, z); |
11039
4cbb08163a1f
Use Octave to create pdf versions of plots for documentation.
Rik <octave@nomad.inbox5.com>
parents:
11033
diff
changeset
|
275 title ("Sorry, graphics are unavailable because Octave was\ncompiled without a sparse matrix implementation."); |
6040 | 276 unwind_protect_cleanup |
20342
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19751
diff
changeset
|
277 print (outfile, d_typ); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
278 hide_output (); |
6040 | 279 end_unwind_protect |
280 endif | |
281 endfunction | |
7262 | 282 |
20351
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
283 function set_print_size () |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
284 image_size = [5.0, 3.5]; # in inches, 16:9 format |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
285 border = 0; # For postscript use 50/72 |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
286 set (0, "defaultfigurepapertype", "<custom>"); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
287 set (0, "defaultfigurepaperorientation", "landscape"); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
288 set (0, "defaultfigurepapersize", image_size + 2*border); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
289 set (0, "defaultfigurepaperposition", [border, border, image_size]); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
290 endfunction |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
291 |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
292 ## Use this function before plotting commands and after every call to |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
293 ## print since print() resets output to stdout (unfortunately, gnpulot |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
294 ## can't pop output as it can the terminal type). |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
295 function hide_output () |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
296 hf = figure (1); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
297 set (hf, "visible", "off"); |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
298 endfunction |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20342
diff
changeset
|
299 |