Mercurial > octave-nkf
annotate doc/interpreter/sparseimages.m @ 19742:1170c849952b
don't force gnuplot for creating figures for documentation
* geometryimages.m, interpimages.m, plotimages.m, sparseimages.m,
splineimages.m: Don't set graphics_toolkit to "gnuplot".
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 13 Feb 2015 14:02:06 -0500 |
parents | 4197fc428c7d |
children | 606b05352351 |
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 | |
6126 | 19 function sparseimages (nm, typ) |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
20 set_print_size (); |
7257 | 21 if (strcmp (typ, "png")) |
22 set (0, "defaulttextfontname", "*"); | |
23 endif | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
24 |
16170
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
25 if (__have_feature__ ("COLAMD") |
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
26 && __have_feature__ ("CHOLMOD") |
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
27 && __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
|
28 if (strcmp (typ,"txt")) |
6126 | 29 txtimages (nm, 15, typ); |
6003 | 30 else |
6126 | 31 if (strcmp (nm, "gplot")) |
11033
d9c8916bb9dd
Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents:
9914
diff
changeset
|
32 gplotimages ("gplot", typ); |
6126 | 33 elseif (strcmp (nm, "grid")) |
11033
d9c8916bb9dd
Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents:
9914
diff
changeset
|
34 femimages ("grid", typ); |
6126 | 35 else |
11033
d9c8916bb9dd
Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents:
9914
diff
changeset
|
36 otherimages (nm, 200, typ); |
6126 | 37 endif |
6003 | 38 endif |
6040 | 39 else ## There is no sparse matrix implementation available because |
40 ## of missing libraries, plot sombreros instead | |
41 sombreroimage (nm, typ); | |
42 endif | |
6003 | 43 endfunction |
44 | |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
45 function set_print_size () |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
46 image_size = [5.0, 3.5]; # in inches, 16:9 format |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
47 border = 0; # For postscript use 50/72 |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
48 set (0, "defaultfigurepapertype", "<custom>"); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
49 set (0, "defaultfigurepaperorientation", "landscape"); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
50 set (0, "defaultfigurepapersize", image_size + 2*border); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
51 set (0, "defaultfigurepaperposition", [border, border, image_size]); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
52 endfunction |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
53 |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
54 function hide_output () |
6257 | 55 f = figure (1); |
56 set (f, "visible", "off"); | |
6003 | 57 endfunction |
58 | |
6040 | 59 function gplotimages (nm, typ) |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
60 hide_output (); |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
61 if (strcmp (typ, "eps")) |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
62 d_typ = "-depsc2"; |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
63 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
64 d_typ = ["-d" typ]; |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
65 endif |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
66 |
6040 | 67 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
|
68 [1,1,2,2,3,3,4,4,5,5,6,6], 1, 6, 6); |
6003 | 69 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
|
70 gplot (A, xy); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
71 print ([nm "." typ], d_typ); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
72 hide_output (); |
6003 | 73 endfunction |
74 | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
75 function txtimages (nm, n, typ) |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
76 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
|
77 sparse (ceil ([1:n]/2),1:n,1,n,n); |
6003 | 78 if (strcmp (nm, "gplot") || strcmp (nm, "grid")) |
79 fid = fopen (sprintf ("%s.txt", nm), "wt"); | |
7256 | 80 fputs (fid, "\n"); |
6003 | 81 fputs (fid, "+---------------------------------+\n"); |
82 fputs (fid, "| Image unavailable in text mode. |\n"); | |
83 fputs (fid, "+---------------------------------+\n"); | |
84 fclose (fid); | |
85 elseif (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
|
86 printsparse (a, ["spmatrix." typ]); |
6003 | 87 else |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
88 if (__have_feature__ ("COLAMD") && __have_feature__ ("CHOLMOD")) |
6003 | 89 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
|
90 r1 = chol (a); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
91 printsparse (r1, ["spchol." typ]); |
6003 | 92 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
|
93 [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
|
94 printsparse(r2, ["spcholperm." typ]); |
6003 | 95 endif |
96 ## printf("Text NNZ: Matrix %d, Chol %d, PermChol %d\n",nnz(a),nnz(r1),nnz(r2)); | |
97 endif | |
98 endif | |
99 endfunction | |
100 | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
101 function otherimages (nm, n, typ) |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
102 hide_output (); |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
103 if (strcmp (typ, "eps")) |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
104 d_typ = "-depsc2"; |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
105 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
106 d_typ = ["-d" typ]; |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
107 endif |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
108 |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
109 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
|
110 sparse (ceil ([1:n]/2),1:n,1,n,n); |
6003 | 111 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
|
112 spy (a); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
113 axis ("ij"); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
114 print (["spmatrix." typ], d_typ); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
115 hide_output (); |
6003 | 116 else |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
117 if (__have_feature__ ("COLAMD") && __have_feature__ ("CHOLMOD")) |
6003 | 118 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
|
119 r1 = chol (a); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
120 spy (r1); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
121 axis ("ij"); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
122 print (["spchol." typ], d_typ); |
11033
d9c8916bb9dd
Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents:
9914
diff
changeset
|
123 hide_output (); |
6003 | 124 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
|
125 [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
|
126 spy (r2); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
127 axis ("ij"); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
128 print (["spcholperm." typ], d_typ); |
11033
d9c8916bb9dd
Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents:
9914
diff
changeset
|
129 hide_output (); |
6003 | 130 endif |
131 ## printf("Image NNZ: Matrix %d, Chol %d, PermChol %d\n",nnz(a),nnz(r1),nnz(r2)); | |
132 endif | |
133 endif | |
134 endfunction | |
135 | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
136 function printsparse (a, nm) |
6003 | 137 fid = fopen (nm,"wt"); |
7256 | 138 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
|
139 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
|
140 if (rem (i,5) == 0) |
6003 | 141 fprintf (fid," %2d - ", i); |
142 else | |
143 fprintf (fid," | "); | |
144 endif | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
145 for j = 1:columns (a) |
6003 | 146 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
|
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"); |
6003 | 153 endfor |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
154 fprintf (fid," |-"); |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
155 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
|
156 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
|
157 fprintf (fid,"-|"); |
6003 | 158 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
159 fprintf (fid,"--"); |
6003 | 160 endif |
161 endfor | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
162 fprintf (fid,"\n"); |
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
163 fprintf (fid," "); |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
164 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
|
165 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
|
166 fprintf (fid,"%2d",j); |
6003 | 167 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
168 fprintf (fid," "); |
6003 | 169 endif |
170 endfor | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
171 fclose (fid); |
6003 | 172 endfunction |
173 | |
11039
4cbb08163a1f
Use Octave to create pdf versions of plots for documentation.
Rik <octave@nomad.inbox5.com>
parents:
11033
diff
changeset
|
174 function femimages (nm, typ) |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
175 hide_output (); |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
176 if (strcmp (typ, "eps")) |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
177 d_typ = "-depsc2"; |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
178 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
179 d_typ = ["-d" typ]; |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
180 endif |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
181 |
16170
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
182 if (__have_feature__ ("COLAMD") |
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
183 && __have_feature__ ("CHOLMOD") |
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
184 && __have_feature__ ("UMFPACK")) |
6003 | 185 ## 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
|
186 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
|
187 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 | 188 nodes = [node_x(:), node_y(:)]; |
189 | |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
190 [h,w] = size (node_x); |
6003 | 191 elems = []; |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
192 for idx = 1 : w-1 |
6003 | 193 widx = (idx-1)*h; |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17887
diff
changeset
|
194 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
|
195 elems = [elems; widx+[(2:h);h+(2:h);h+(1:h-1)]']; |
6003 | 196 endfor |
197 | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
198 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
|
199 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
|
200 D = size (elems,2); # dimensions+1 |
6003 | 201 |
202 ## Plot FEM Geometry | |
203 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
|
204 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
|
205 yelems = reshape (nodes(elemx, 2), 4, E); |
6003 | 206 |
207 ## 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
|
208 conductivity = [1*ones(1,16), 2*ones(1,48), 1*ones(1,16)]; |
6003 | 209 |
210 ## Dirichlet boundary conditions | |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17887
diff
changeset
|
211 D_nodes = [1:5, 51:55]; |
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17887
diff
changeset
|
212 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
|
213 |
6003 | 214 ## Neumann boundary conditions |
215 ## Note that N_value must be normalized by the boundary | |
216 ## length and element conductivity | |
217 N_nodes = []; | |
218 N_value = []; | |
219 | |
220 ## 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
|
221 C = sparse ((1:D*E), reshape (elems',D*E,1),1, D*E, N); |
6003 | 222 |
223 ## 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
|
224 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
|
225 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
|
226 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
|
227 dfact = prod (2:(D-1)); |
6003 | 228 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
|
229 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
|
230 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
|
231 Sdata(D*(j-1)+(1:D),:) = const * a(2:D,:)'*a(2:D,:); |
6003 | 232 endfor |
233 | |
234 ## 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
|
235 SE = sparse (Siidx,Sjidx,Sdata); |
6003 | 236 ## Global system matrix |
237 S = C'* SE *C; | |
238 | |
239 ## 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
|
240 V = zeros (N,1); |
6003 | 241 V(D_nodes) = D_value; |
242 idx = 1:N; | |
243 idx(D_nodes) = []; | |
244 | |
245 ## 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
|
246 Q = zeros (N,1); |
6003 | 247 Q(N_nodes) = N_value; # FIXME |
248 | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
249 V(idx) = S(idx,idx) \ ( Q(idx) - S(idx,D_nodes)*V(D_nodes) ); |
6003 | 250 |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
251 velems = reshape (V(elemx), 4, E); |
6178 | 252 |
253 plot3 (xelems, yelems, velems); | |
17887
3252b366bb5d
sparseimages.m: Fix incorrect view() command for printed image.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
254 view (80, 10); |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
255 print ([nm "." typ], d_typ); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
256 hide_output (); |
6003 | 257 endif |
258 endfunction | |
6040 | 259 |
260 ## There is no sparse matrix implementation available because of missing | |
261 ## libraries, plot sombreros instead. Also plot a nice title that we are | |
262 ## sorry about that. | |
263 function sombreroimage (nm, typ) | |
264 if (strcmp (typ, "txt")) | |
265 fid = fopen (sprintf ("%s.txt", nm), "wt"); | |
7256 | 266 fputs (fid, "\n"); |
6040 | 267 fputs (fid, "+---------------------------------------+\n"); |
268 fputs (fid, "| Image unavailable because of a |\n"); | |
269 fputs (fid, "| missing sparse matrix implementation. |\n"); | |
270 fputs (fid, "+---------------------------------------+\n"); | |
271 fclose (fid); | |
272 return; | |
273 else ## if (!strcmp (typ, "txt")) | |
274 | |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
275 hide_output (); |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
276 if (strcmp (typ, "eps")) |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
277 d_typ = "-depsc2"; |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
278 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
279 d_typ = ["-d" typ]; |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
280 endif |
6040 | 281 |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
282 [x, y, z] = sombrero (); |
6040 | 283 unwind_protect |
6257 | 284 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
|
285 title ("Sorry, graphics are unavailable because Octave was\ncompiled without a sparse matrix implementation."); |
6040 | 286 unwind_protect_cleanup |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16170
diff
changeset
|
287 print ([nm "." typ], d_typ); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
288 hide_output (); |
6040 | 289 end_unwind_protect |
290 endif | |
291 endfunction | |
7262 | 292 |
293 ## generate something for the texinfo @image command to process | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
294 function image_as_txt (nm) |
7262 | 295 fid = fopen (sprintf ("%s.txt", nm), "wt"); |
296 fputs (fid, "\n"); | |
297 fputs (fid, "+---------------------------------+\n"); | |
298 fputs (fid, "| Image unavailable in text mode. |\n"); | |
299 fputs (fid, "+---------------------------------+\n"); | |
300 fclose (fid); | |
301 endfunction | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
302 |