MATLAB Mathematics - SERC - Index of
MATLAB Mathematics - SERC - Index of MATLAB Mathematics - SERC - Index of
6 Sparse Matrices Now F = full(S) displays the corresponding full matrix. F = full(S) F = -2 1 0 0 0 1 -2 1 0 0 0 1 -2 1 0 0 0 1 -2 1 0 0 0 1 -2 Creating Sparse Matrices from Their Diagonal Elements Creating sparse matrices based on their diagonal elements is a common operation, so the function spdiags handles this task. Its syntax is S = spdiags(B,d,m,n) To create an output matrix S of size m-by-n with elements on p diagonals: • B is a matrix of size min(m,n)-by-p. The columns of B are the values to populate the diagonals of S. • d is a vector of length p whose integer elements specify which diagonals of S to populate. That is, the elements in column j of B fill the diagonal specified by element j of d. Note If a column of B is longer than the diagonal it’s replacing, super-diagonals are taken from the lower part of the column of B, and sub-diagonals are taken from the upper part of the column of B. As an example, consider the matrix B and the vector d. B = [ 41 11 0 52 22 0 63 33 13 74 44 24 ]; 6-10
Introduction d = [-3 0 2]; Use these matrices to create a 7-by-4 sparse matrix A. A = spdiags(B,d,7,4) A = (1,1) 11 (4,1) 41 (2,2) 22 (5,2) 52 (1,3) 13 (3,3) 33 (6,3) 63 (2,4) 24 (4,4) 44 (7,4) 74 In its full form, A looks like this. full(A) ans = 11 0 13 0 0 22 0 24 0 0 33 0 41 0 0 44 0 52 0 0 0 0 63 0 0 0 0 74 spdiags can also extract diagonal elements from a sparse matrix, or replace matrix diagonal elements with new values. Type help spdiags for details. 6-11
- Page 200 and 201: 5 Differential Equations The input
- Page 202 and 203: 5 Differential Equations 2 Pass the
- Page 204 and 205: 5 Differential Equations 3 Code the
- Page 206 and 207: 5 Differential Equations Finding Un
- Page 208 and 209: 5 Differential Equations vectorized
- Page 210 and 211: 5 Differential Equations There is a
- Page 212 and 213: 5 Differential Equations 3 Solve on
- Page 214 and 215: 5 Differential Equations hold off T
- Page 216 and 217: 5 Differential Equations Note The d
- Page 218 and 219: 5 Differential Equations legend('An
- Page 220 and 221: 5 Differential Equations Here, v(1-
- Page 222 and 223: 5 Differential Equations solution v
- Page 224 and 225: 5 Differential Equations Note The D
- Page 226 and 227: 5 Differential Equations After disc
- Page 228 and 229: 5 Differential Equations The output
- Page 230 and 231: 5 Differential Equations 2 Code the
- Page 232 and 233: 5 Differential Equations Note See t
- Page 234 and 235: 5 Differential Equations The exampl
- Page 236 and 237: 5 Differential Equations and the ri
- Page 238 and 239: 5 Differential Equations u1(x,t) 1
- Page 240 and 241: 5 Differential Equations Selected B
- Page 242 and 243: 6 Sparse Matrices Function Summary
- Page 244 and 245: 6 Sparse Matrices Function Summary
- Page 246 and 247: 6 Sparse Matrices This matrix requi
- Page 248 and 249: 6 Sparse Matrices S = (3,1) 1 (2,2)
- Page 252 and 253: 6 Sparse Matrices Importing Sparse
- Page 254 and 255: 6 Sparse Matrices west0479 west0479
- Page 256 and 257: 6 Sparse Matrices The find Function
- Page 258 and 259: 6 Sparse Matrices of the rows and c
- Page 260 and 261: 6 Sparse Matrices The vertices of o
- Page 262 and 263: 6 Sparse Matrices 0 10 20 30 40 50
- Page 264 and 265: 6 Sparse Matrices 0 500 1000 1500 2
- Page 266 and 267: 6 Sparse Matrices simply sparse(m,n
- Page 268 and 269: 6 Sparse Matrices Similarly, S(:,p)
- Page 270 and 271: 6 Sparse Matrices The following MAT
- Page 272 and 273: 6 Sparse Matrices 0 Original 0 Reve
- Page 274 and 275: 6 Sparse Matrices QR Factorization
- Page 276 and 277: 6 Sparse Matrices shows that A has
- Page 278 and 279: 6 Sparse Matrices Functions for Ite
- Page 280 and 281: 6 Sparse Matrices set up the five-p
- Page 282 and 283: 6 Sparse Matrices Manipulating Spar
- Page 284 and 285: 6 Sparse Matrices Selected Bibliogr
- Page 286 and 287: Index comparing sparse and full mat
- Page 288 and 289: Index H hb1dae demo 5-35 hb1ode dem
- Page 290 and 291: Index nonstiff ODE examples rigid b
- Page 292 and 293: Index LU factorization 6-30 minimum
- Page 294: Index twobvp demo 5-63 two-dimensio
6 Sparse Matrices<br />
Now F = full(S) displays the corresponding full matrix.<br />
F = full(S)<br />
F =<br />
-2 1 0 0 0<br />
1 -2 1 0 0<br />
0 1 -2 1 0<br />
0 0 1 -2 1<br />
0 0 0 1 -2<br />
Creating Sparse Matrices from Their Diagonal Elements<br />
Creating sparse matrices based on their diagonal elements is a common<br />
operation, so the function spdiags handles this task. Its syntax is<br />
S = spdiags(B,d,m,n)<br />
To create an output matrix S <strong>of</strong> size m-by-n with elements on p diagonals:<br />
• B is a matrix <strong>of</strong> size min(m,n)-by-p. The columns <strong>of</strong> B are the values to<br />
populate the diagonals <strong>of</strong> S.<br />
• d is a vector <strong>of</strong> length p whose integer elements specify which diagonals <strong>of</strong> S<br />
to populate.<br />
That is, the elements in column j <strong>of</strong> B fill the diagonal specified by element j<br />
<strong>of</strong> d.<br />
Note If a column <strong>of</strong> B is longer than the diagonal it’s replacing,<br />
super-diagonals are taken from the lower part <strong>of</strong> the column <strong>of</strong> B, and<br />
sub-diagonals are taken from the upper part <strong>of</strong> the column <strong>of</strong> B.<br />
As an example, consider the matrix B and the vector d.<br />
B = [ 41 11 0<br />
52 22 0<br />
63 33 13<br />
74 44 24 ];<br />
6-10