CS310 Team Lab #6
Linear Systems: So a Bug Walks Onto a Bar ...
Unit 2: Intro to MATLAB & Numeric Computation

bar with 9 real points and 2 fictitious points

1 Fictitious point
9 Real points
1 Fictitious point

PROBLEMS

Problem 1: Model the problem as a linear system in matrix form. (Do parts a - c on paper)

  1. For each position, write a linear equation that computes the number of steps on average it takes a bug starting at that position to fall off the bar.

  2. Reorder the terms in each equation so that each equation is in general form.

    General form has the unknown terms on the left and the constants on the right of the equals sign. It will be helpful to write your equations so that all unknown terms "line up" with the corresponding unknown terms of the other equations.

  3. Write the system as a single matrix equation.

    Put the coefficients of the unknowns in a matrix and show the multiplication of that matrix with a column vector of the unknown variables, T1 through Tn, and set that equal to a column vector of the constants or known values.

    Show your equations to a Lab Leader

  4. Create a new script. Inside the script, add code to create the coefficient matrix and assign it to the name A.

    The matrix A is a matrix of the coefficients of the unknown terms (Tk). 

    These commands can get you started. Note that putting each row of the matrix on a separate line improves readability and makes it easier to spot typos. Also note that if you put each row on a separate line when you are defining a matrix (as you are here), you don't need to end each line with ... (dot,dot,dot) to continue the statement on the next line.

    A = [1 0 0 0 0 0 0 0 0 0 0;
    -.5 1 -.5 0 0 0 0 0 0 0 0;
    and so on ... until the last row
    0 0 0 0 0 0 0 0 0 0 1];

  5. Enter the data vector (right hand side column of the system) as a column vector named b.

    b =

  6. Use MATLAB's backslash operator to solve for the unknowns T.

    T = A \ b

    Don't forget to run your script. Do your results make sense (e.g., are all the values in T non-negative)?

Problem 2: ... but, there are holes in the bar

Now create a linear system for the bar (below) which has a hole in it. The hole looks like a fictitious point in the middle area of the bar. Remember that the equation for a fictitious point is Tk=0. You need to revise the equation to account for the hole in the linear system.

9 position bar with a hole (fictitious point) at position 5

You may have noticed that if the bar has holes in it, then the problem decomposes into separate problems, one for each section.  However, we don't need to solve it as two problems, we just need to modify the equations and solve the new system. In the next section we will consider two-dimensional problems with holes, and these one-dimensional problems with holes are a good warm-up for the two-dimensional problems.

Problem 3: ... and he asks the bartender for a plate

Let's take this problem to two dimensions. There is a bug on a plate and it can hop north, south, east, or west.  The average number of steps is still determined in the same way: it is the average of the points around it, plus one step to get to the next position. Here is the equation for a point p

Formula for point, p: Tp=(Tn+Ts+Te+Tw)4+1

where n, s, e, and w refer to the surrounding points to the north, south, east and west of point p.  We have included a diagram to help you get started.

A 3x3 plate with a border of fictitious points.  (really, it is 5x5)

  1. Create a system of linear equations that will solve for every point on the plate.

    First, number the points from 1 to 25 on diagram.  Then determine the equations for each point, including the fictitious points.

    Show your equations for plate positions 6, 7, 12, 13, 18, 19 to a Lab Leader

  2. Enter the coefficient matrix.  (Hint: the matrix will have one unknown for each position on the plate. Keep reading for a way to enter this matrix that is more efficient than manually typing every entry.)

    Try using the identity matrix function, A = eye(25,25), to get the coefficient matrix started.

    One way you can create the coefficient matrix is to write the commands in a script that can be saved, edited, and re-executed as needed. After using the eye function, you need to set other values in just the rows that correspond to positions on the plate. Use commands similar to the following: A(2,[1,3])=-1/2 (which sets the values at columns 1 and 3 of row 2 of matrix A to the value -1/2).

  3. Enter the right hand side column data vector. To make entering easier, remember that you can use built-in MATLAB functions like zeros() and ones() which can be useful for creating large matrices and vectors.

  4. Solve the linear system.

  5. Display the 25 solution values in the same organization as the plate (i.e., a 5×5 grid of corresponding values instead of a single list of 25 values). Hint: use your MATLAB skills to create a matrix containing the pieces of your solution vector in the format you want them.

    Show your solution in the 5×5 grid format to a Lab Leader

Problem 4: ... but, there are holes in the plate, too!

Now let's consider a plate with holes:

plate with holes

Modify your linear system from problem 3 to account for the holes and solve it. As in part 3.e, display the solution values in the same organization as the plate.

Here's another plate with holes for you to try (note that this plate is 4×4):

another plate with holes

ADDITIONAL PROBLEMS or FURTHER READING

A simple DC circuit is given below:

circuit

Given the voltages and resistances in the branches, we wish to compute the currents. Resistances are given in Ohms (Ω), there is an applied voltage (V), and arrows indicate the direction of positive current. The basic principles for DC circuits are expressed as Kirchhoff's Laws. These two laws give the set of linear equations that need to be solved to obtain the currents (labelled with i's in the diagram).

Kirchhoff's First Law: (node equations) The sum of the current flowing into a node must be equal to the sum of the current flowing out of the node.

This leads to the following equations for the nodes:

Note that the equations for nodes A, D, G, E, and F are redundant and can be thrown out.

Kirchhoff's Second Law: (loop equations) The sum of the products of the resistance (Ohms) times the current around a cycle will be zero.

This leads to the following equations for loops:

Note that the loop equation for loop 4 provides redundant information and thus finding every possible cycle is not necessary. Simply find non-redundant cycles.

You will need to assign a value for the voltage to actually solve the linear system. Try V=6 and V=9.