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