$39.99
This “Justin’s Guide” is an edited version of a guide by Justin Wyss-Gallifent. It is an instructional guide before the actual assignment, with information you will need to have. You do not need to turn in anything for this part. The actual assignment starts a few pages down.
1. Method
The way this guide is written is that it is assumed that you will sit down at a MATLAB terminal and start. The commands that you give to MATLAB are given but the output is not. The output is, however, discussed, with the understanding that you will run the commands and see the output. Then you can read about it and keep going.
2. Starting MATLAB
3. Simple Calculation
For example, to do 4+5 we just type it in and hit “return”
>> 4+5
4. Solving a System
Now let’s do something having to do with MATH 240/461.
3x1 + x2 − 5x3 = 0 x1 − 5x2 + x3 = 2 x1 + x2 − 5x3 = −1
What we type in is the following.
>> [x1 x2 x3]=solve(’3*x1+x2-5*x3=0’,’x1-5*x2+x3=2’,’x1+x2-5*x3=-1’)
Note the apostrophes (single quotes). They are necessary because an equation must be treated as a string of characters and strings of characters in MATLAB are delimited by apostrophes.
Note here that we got three solutions. What would happen if we fed MATLAB a system with not enough equations? Let’s try!
>> [x1 x2 x3]=solve(’3*x1+x2-5*x3=0’,’x1-5*x2+x3=2’)
If you try this, MATLAB chokes. (Mine didn’t.) The reason is that it doesn’t know what to do or how to give the solution. There are ways for MATLAB to solve this but they demand that we know more than we do, too. For now we’ll need to deal with the corresponding augmented matrices in order to get MATLAB to help us solve this system.
5. Putting in a Matrix
We can put in a matrix easily. To put in
we do
>> A=[2 3 ; 5 -1]
6. Matrix Operations
Suppose now you put in a matrix and you wish to manually do row operations to it. MATLAB doesn’t have any functions for doing row operations, instead we have to execute low-level commands to do so. This is easier than it seems.
Here is an augmented matrix
>> A=[1 -1 -3 7 ; -3 1 4 -16 ; 4 -3 -5 12]
To get this to row-echelon form, first we’ll clean out the entries below the upper-left 1. To do this we need to add 3 times row 1 to row 2. In MATLAB the code is
>> A(2,:)=A(2,:)+3*A(1,:)
The expression A(rownumber,:) refers to the entire row, so basically this line is saying:
Row2 Row2 3∗Row1
Try it! The result will be given.
Next we’ll add −4 times row 1 to row 3.
>> A(3,:)=A(3,:)+(-4)*A(1,:)
Now you’ll see that we have 0s below the upper-left 1. Next we need to get a 0 in the bottom row where the 1 is. The easiest way to do this is first to interchange rows 2 and 3.
>> A([2 3],:)=A([3 2],:)
(Can you decipher what each key part of this code represents in interchanging the two rows?) Now we add twice row 2 to row 3.
>> A(3,:)=A(3,:)+2*A(2,:)
The result you’ll see is the matrix in (echelon or) row-echelon form.
To get to (reduced echelon or) reduced row-echelon form, we first have to get 1s for all our leading entries. The third row is the only problem, it needs to be multiplied by 1/9.
>> A(3,:)=1/9*A(3,:)
This means that row 3 is 1/9 times what it was.
Lastly we must turn the entries above the leading 1s into 0s.
We begin above the rightmost leading 1.
>> A(1,:)=A(1,:)+3*A(3,:)
>> A(2,:)=A(2,:)+(-7)*A(3,:)
And then above the leading 1 to the left of that one.
>> A(1,:)=A(1,:)+1*A(2,:)
The result is now in reduced row-echelon form. Since there are no free variables we can simply read off the solution: x1 = 3, x2 = 5 and x3 = −3.
7. Skipping to the Reduced Row-Echelon Form
Suppose now you want to solve a system of matrices by getting the augmented matrix in reduced row-echelon form but you don’t want to do all that work on the previous page. The rref command does this in MATLAB. For example if I put in the augmented matrix (corresponding to a system of linear equations) for the previous page’s problem:
>> A=[1 -1 -3 7 ; -3 1 4 -16 ; 4 -3 -5 12] and then reduce it
>> rref(A) we see that MATLAB saves us time compared to all the work we needed to do on the previous page.
Here is another problem. This one has free variables at the end. We will see that after rref because there are non-pivot columns corresponding to some variables.
>> A=[1 3 4 2;1 -3 0 1] and then reduce it
>> rref(A)
We get the reduced form. Its entries are in decimal form, but clearly it corresponds to the augmented matrix
Note that the third column is not a pivot column so x3 is free. Hence we have the solution
x3 = free
8. Lastly, note that we can deal with matrices with unknown constants in them but we have to explicitly tell MATLAB that they are unknown constants. For example, suppose we wish to enter the matrix
First we must tell MATLAB that h and k are to be dealt with symbolically. We do this with the syms command
>> syms h >> syms k
And now we can do
>> A=[-2 3 h ; 5 -1 k]
>> rref(A)
(The matrix was a bit strange. It was in the form of two rows enclosed by square brackets with commas between entries.)
Format directions: Please do your work in MATLAB’s “Editor” window. That way you can click on the “Publish” to get a clear finished document for submission. Please organize your work well and submit a “published” document. You will be submitting an electronic version your MATLAB assignment on ELMS.
You will need to include items in your submission that are not MATLAB commands. For example, your name. You can do this by typing into the MATLAB prompt >> your name, preceded by the percent symbol %. MATLAB ignores the “comment” you type on a line following this symbol. For example, if your name were Homer Simpson, your first lines could look like
>> % Homer Simpson
>> % Other group members: Ned Flanders, Sideshow Bob
Separate each problem number into its own section, before each problem number, by typing
>> %%
Also, when you begin a new problem part, indicate that on the output with something like
>> % Problem 1(a)
It is imperative that you do this as it will make your work easier to follow and show that you understand the terminology of each part of the question and are not just blindly going to the last part of the question.
>> % Problem 1(a). Here is the augmented matrix A.
Below, a question marked with a star ⋆ is to be answered with a typed in answer, following the % .
But first: Before you start, if you are new to MATLAB, go through “Justin’s Guide” and type along in MATLAB as you read. That should be enough to get you through this project. You mat also want to click on the “Learn MATLAB” link that can be found on the far right after clicking the “Home” tab. At that link, you will find the MATLAB On Ramp which will help familiarize you with MATLAB in general. Don’t turn in anything from your interactive work mentioned above. To start fresh, click on the + at the top of the editor window to get a new tab.
Clearing: For safety, before each question, you can type clear to clear out the memory.
Format: The command “format rat” will cause your matrix outputs to appear as fractions. You might find that convenient or necessary at times. The command “format short” changes back to the standard format.
Free response: For example, if you are asked to put a matrix in a certain form, and your matrix is already in that form, then just answer with some comment line such as % The matrix is already in reduced echelon form.
The project problems begin here.
1. Consider the system of equations
x1 + 2x2 − 3x3 = −3
−4x1 − 5x2 + 2x3 = −2
2x1 + 3x2 − x3 = 2
(a) Enter it into MATLAB as an (augmented) matrix named A.
(b) Use elementary row operations (as in part 6 of the guide) to reduce it to row-echelon form.
(c) Continue to reduced row-echelon form.
(d) ⋆ Give the solution of the system.
(If the system has no solution, say that. Otherwise, write the basic variables as functions of the free variables, if there are any.) 2. Consider the system of equations
x1 + 3x3 + x5 = −1
x1 + x2 + x3 + 6x5 = 1
−3x1 − 3x2 − 3x3 + x4 − 19x5 = 6
10x1 − 4x2 + 38x3 + 2x4 − 12x5 = 0
(a) Enter it into MATLAB as an (augmented) matrix named B.
(b) Use elementary row operations (as in part 6 of the guide) to reduce it to row-echelon form.
(c) ⋆ Is the system consistent or inconsistent? If it is consistent, does it have a unique solution or infinitely many solutions? Explain how you know.
3. Enter the (augmented) matrix
(a) Convert it to reduced row-echelon form using rref.
(b) Convert the matrix entries to fractions instead of decimals.
(c) ⋆ Write the solution of the system which corresponds to this matrix.
4. Suppose you wish to show that is in the span of for any a and b.
(a) First declare a and b as symbolic (unknown constants).
(b) Enter a matrix A which can help you show this.
(c) Use rref on the matrix A.
(d) ⋆ Explicitly give the weights w1 and w2 such that .
5. Suppose you wish to show that the set of vectors
is linearly dependent.
(a) Enter a matrix A which can help you solve this.
(b) Use rref on the matrix A.
(c) ⋆ Give a nontrivial linear combination of the vectors which yields 0.
6. Suppose you wish to show that
is not in the span of
(a) Use rref on an appropriate matrix to show this fact.
(b) ⋆ Explain why your calculation in (a) is sufficient.