Title: Solving Linear Systems cont Example systems
1Solving Linear Systems cont(Example systems)
- Lecture 18
- CAAM 420
- Fall 2004
2Note
- It is important that at least one loop has
aresistor that lies only on that loop (i.e. at
least one resistor lying on a wire not shared by
two loops). - Otherwise the entire circuit will short circuit
around the boundary of the entire circuit.. - For example
9
9
8
8
1W
1W
4W
4W
6W
6W
4
5
4
5
3W
3W
7W
7W
-
1
-
1
1W
2
3
1W
2
3
2W
2W
3Class Exercise
a) Create a non-trivial circuit with 15 sub
loops. Use a range of resistor values between 1
and 10. b) Solve for loop currents with
Matlab c) Draw a diagram indicating current
along each segment of circuit (to two significant
figures). d) Verify Kerchoffs first law (look
it up) by checking the sum of currents at three
of the wire intersections. e) Count the number
of non-zeros of your 15x15 matrix and report the
amount of fill (i.e. number of non-zeros/225) f)
Include print out of matlab window used for
matrix solution.
4Circuit Problem Enlarged
9
8
1W
5W
2W
1W
4W
6W
4
5
3W
7W
1
-
10V
2
3
1W
5W
2W
1W
4W
6W
11
15
3W
7W
7
-
20V
12
17
1W
5W
2W
1W
4W
6W
6
16
3W
7W
Problem Find the current running through each
closed loop
-
30V
10
14
13
2W
1W
5Shortcut to Loop Current Matrix
9
8
1W
5W
2W
1W
4W
6W
4
5
3W
7W
1
-
10V
2
3
1W
5W
- To obtain the nth row of the
- Matrix
- The diagonal entry is equal to the sum of the
resistances on the nth loop - There is an off diagonal entry foreach neighbor
of the loop which is equal toa)
sum(resistances) on shared wire if loop
currents are in opposite direction b)
sum(resistances) on shared wire if loop
currents are in the same direction
2W
1W
4W
6W
11
15
3W
7W
7
-
20V
12
17
1W
5W
2W
1W
4W
6W
6
16
3W
7W
-
30V
10
14
13
2W
1W
69
8
1W
5W
2W
1W
4W
6W
4
5
3W
7W
1
-
2
3
1W
5W
2W
1W
4W
6W
11
15
3W
7W
7
-
12
17
1W
5W
2W
1W
4W
6W
6
16
3W
7W
-
10
14
13
2W
1W
7Using Sparse Matrices in Matlab
row,column,entry
8Run bigcircuit
- Create the list of non-zeros
- Convert the list to Matlabs sparse matrix format
- Convert the sparse matrix to a full matrix (just
for viewing)
9Counting the Non-Zeros with nnz
- We can use Matlabs built in nnz function to find
the number of non-zeros
i.e. there are only 58 non-zero entries out of
17x17289 possible
10Sparse Matrices
- When the fill ratio of a matrix is small (i.e.
very few non-zero entries in the matrix) we can
use an alternative to storing all the entries in
the matrix. - Next time we will discuss different ways to store
the non-zero entries, omitting the zeros. - We will then review available libraries designed
to allow manipulation of sparse matrices.
Valuable references and online book
http//www-users.cs.umn.edu/saad/books.html
11Storage Conventions
- There are many different conventions used to
store a sparse matrix. - Refer to ftp//ftp.cs.umn.edu/dept/users/saad/PS/i
ter1.pdf - Chapter 3 Sparse Matrices page 84-- for
details - We will briefly cover 3 common methods to store
the non-zero entries of a sparse matrix - compressed sparse row
- compressed sparse column
- coordinate format
12Compressed Sparse Row Convention
- Row compressed
- Imagine we take a row major dmat (indexed from 1)
and strip out the zero entries from the storage
vector - At the same time we also create two arrays used
for indexing - The first array has nrows1 int entries.
- The nth entry is the location in the stripped
storage vector of the first non-zero entry for
row n of the matrix. - The last entry in this array is the number of
non-zeros1. - The second array of ints is the same size as
the stripped storage vector and contains the
column number of each entry.
13Example
- Suppose our original matrix is
- Then the non-zero entries (in row-major ordering)
are - The array of location in non-zero entries of
first entry on a row is where we
have padded the last entry to be the total number
of non-zero entries 1 - Finally, the vector of column numbers for each
entry are
14Class Exercise (compressed sparse row format)
What is the non-zero entries matrix
( ) What is
the first non-zero entry in a row locator (
) What is the column index per
non-zero entry array ( )
15Compressed Sparse Column Convention
- Same as row-condensed version but this time the
columns are treated instead of the rows.
16Class Exercise (compressed sparse column format)
What is the non-zero entries matrix
( ) What is
the first non-zero entry in a row locator (
) What is the column index per
non-zero entry array ( )
17Coordinate Format Storage
- An easier format stores each non-zero entry
directly stores the coordinates and value of the
entry, namely - (row number,column number, entry value)
18Some Software for Sparse Matrices
- SPARSKIT (includes BLAS type functionality for
sparse matrices) - http//www-users.cs.umn.edu/saad/software/SPARSKI
T/sparskit.html - ftp//ftp.cs.umn.edu/dept/sparse/
- UMFPACK (includes fast multi frontal solvers for
sparse matrices) - http//www.cise.ufl.edu/research/sparse/umfpack/
19Class Exercise (using a library from the web)
- For the following make a directory /tmp/username
- You will work in this directory (to avoid going
over your quota in your home directory) - Download SPARSKIT2 from the ftp link at
- http//www-users.cs.umn.edu/saad/software/SPARSKI
T/sparskit.html - Use gzip and tar to extract the contents of the
downloaded file. - Examine the contents of the directory which is
created. Wait for further instructions.