[SOLVED] C math matlab 221 MATLAB ASSIGNMENT 02

$25

File Name: C_math_matlab_221_MATLAB_ASSIGNMENT_02.zip
File Size: 357.96 KB

5/5 - (1 vote)

221 MATLAB ASSIGNMENT 02
DUE 4 OCTOBER 2018
In this assignment we will consider a little bit of manipulating matrices, and we will also use the computer to solve questions about span and linear independence.
This assignment comes with a file Ex2Data.mat. Import this file as you did in Exercise 1refer to Exercise 1 if you cant remember how.
DECOMPOSING AND RECOMPOSING ELEMENTS OF MATRICES
There is a 1210 matrix C in the file. To see it, type >> C
A useful command we might need later is size. This tells you the size of a matrix or vector. Try
>> size(C)
Itshouldgiveyou12 10.ThisinformationisalsointheWorkspace. To refer to specific entries of C , type
>> C(1,1), C(4,7)
and so on. Check that C(1,1) really does equal the element in the top left of the matrix, i.e., the element in the (1, 1)-position.
We will often want to go between a matrixthought of as a collection of column-vectors all togetherand the individual column vectors. Try
>> C(:, 1), C(:,2), C(:,3)
Note that these are precisely the first three columns of C. The notation : gives you all the different applicable
entries in that position. Also try
>> C(3:7, 1)
Notice that you get the entries in the (3, 1), (4, 1), (5, 1), (6, 1) and (7, 1)-positions in C , all arranged in a column vector. Of course, you can do the same thing for rows. Try
C(1, :), C(1, 3:7)
Making an augmented matrix. Now lets see if we can enlarge a matrix by appending a column. There should be a vector v1 in the data file. Check to see its size
>> size(v1)
It is exactly the same length as the columns of C. Lets produce a new matrix that combines C with v1. >> Caug = [C v1]
The matrix Caug is the augmented matrix associated to the linear system
Cx=v1
Lets check to see if this system has a solution, that is, if v1 lies in the span of the columns of C :
>> rref(Caug)
Observe that the resulting reduced row echelon form represents an inconsistent system, so there is no solution.
Morechoppingup,puttingtogether. Thissubsectiondescribessomemoredecomposingandrecombiningideas. You can extract sub-matrices from a matrix. For example, try
>> C(1:4, 2:5)
Figure out for yourself which elements of C appear in this matrix.
An operation, which we have not encountered yet in class, but is sometimes useful in this context is transpose.
In MATLAB, it is given by the apostrophe symbol . It simply swaps the rows with the columns. For instance, try 1

2 DUE 4 OCTOBER 2018
>> v1
and if you like
>> C
You can also combine more than two things together. For instance try
>> [v1, 2*v1, -v1, ones(12,2)]
You may recall that ones(12,2) gives you a 12 2 matrix, entirely filled with 1s.
REMINDER ABOUT TEXT
In the exercises that follow, some of the answers are supposed to be text, not numbers. Remember from Exercise 1 that you can assign a text value to a variable by, for instance:
>> exampleText = Stately, plump Buck Mulligan Dont forget the quotation marks .
Exercise 1.
(a) Thereare5vectorsinthedatafile,w1, w2, w3, w4, w5.Oneofthem,w4,waswronglysavedasarowvector, the others are column vectors. Replace w4 by the column vector having the same entries in the same order. Thenmakethematrixhavingcolumnsw1 w2 w3 w4 w5.SavetheanswerasOneAmat.
(b) Do the vectors w1, w2, w3, w4, w5 form a linearly independent set (once youve made w4 into a column vector of course)? Store either yes or no in OneBword.
(c) ThereisamatrixDandavectory1inthedatafile.MaketheaugmentedmatrixrepresentingthesystemDx= y1do not row-reduce this matrix yet. Save the matrix as OneCmat.
(d) Isy1inthespanofthecolumnsofD?StoreeitheryesornoinOneDword.
(e) There is another vector y2 in the data file. Calculate the sizes of D and of y2. Is y2 in the span of the columns
of D? Store either yes or no in OneEword
You can use the function
RANDOM NUMBERS
>> rand()
to produce a random1 number between 0 and 1. Notice that rand() has parentheses, to indicate that it is indeed
a function, but those parentheses, (), are empty. Putting a natural number into this, as in
>> rand(4)
generates a 4 4 matrix with random entries, between 0 and 1. To make a nonsquare matrix, you can write >> rand(4,7)
etc.
If you want a matrix filled with random entries that are bigger or smaller than this, you can scale the answer by
multiplying. For instance
>> 0.01 * rand(6)
will produce a 6 6 matrix filled with random numbers between 0 and 0.01. To test yourself, try to figure out what sort of matrix the command
>> 4 * rand(10) 2 * ones(10)
will produce, then try it out.
1Strictly speaking, the numbers produced are pseudorandom because doing exactly the same things will result in the same sequence of apparently random numbers

221 MATLAB ASSIGNMENT 02 3
What does a typical matrix look like? The purpose of this section is to investigate what a typical matrix looks like after you reduce to row echelon form. To test this out, lets fix a size of matrix, say 86, and lets make a random matrix
>> Mrand=rand(8,6)
now take the reduced row echelon form
>> rref(Mrand)
Almost certainly you will see that this matrix has a pivot position in every column. If, somehow, you did not see this, you have encountered an extremely improbable event. If you try the calculation a second time with a new random matrix, you should see a pivot in every column.
Now try with a different size of matrix
>> Nrand = rand(7, 11)
and
>> rref(Nrand)
Again, you will see a pivot position in every column, until you run out of columns. If you prefer to run this experiment with matrices of integers, try
>> Orand = randi(20, 9, 9)
and
>> rref(Orand)
You can repeat this experiment as often as you like, changing the numbers, to see what answers you get.
Exercise 2.
(a) Some vectors are given in the data file: z1, z2, z3, z4, z5. These vectors are not linearly independent, as you can see as follows: make the matrix having these vectors for columns, in the given order. Save it as TwoAmat.
(b) CalculatethereducedrowechelonformofTwoAmat,storingitasTwoBmat.
(c) Importantstep:giveMATLABthecommand
>> rng(N)
where N is your student number. You do not have to store anything in this step, but itll ensure that the random
numbers you produce in the next answer are different from everyone elses.
(d) Add a small amount of random noise or error, no more than 0.1, to each of the vectors z1, z2, z3, z4,
z5 and store the result in a single matrix TwoDmatHint: you can just do
>> TwoDmat = TwoAmat + 0.1*rand(n,m)
for the appropriate values of n and m.
(e) Finally, determine whether the columns of TwoDmat are linearly independent. Store either yes or no in
TwoEword.

4 DUE 4 OCTOBER 2018
HANDING IN
It is now time to turn in your second MATLAB assignment for this course. Again you will be handing in your assignment as a .mat filethat is a matlab file containing all your variables.
Heres how:
(1) Check that you have a value stored for each of the questions you were asked this week. Your Workspace should contain: OneAmat, OneBword, OneCmat, OneDword, OneEword,TwoAmat, TwoBmat, TwoDmat, TwoEword. Please be aware that these names are case-sensitive. If you submit oneamat, for instance, there is a good chance we will mark your assignment as wrong. It is ok if your Workspace contains other variables as well,
we will ignore them.
(2) Save all your variables as a .mat filedo not make a .m file by mistake. There are several ways of doing
this, depending on how you are running MATLAB.
Ifyoureusingmatlab.mathworks.com,youshouldsaveyourvariablesusingthecommand
>> save Math221Assignment2
This will save the variables in a file called Math221Assignment2.mat in mathworks cloud storage. Then you will have to download it to the computer by selecting the file and using the download button:
FIGURE 1. A screenshot of someone saving Math221Assignment1.mat. The procedure for As- signment 2 is the same.
IfyouarerunningMATLABonacomputerlocally,thisisdonebyclickingtheSaveworkspacebutton near the top of the screen.
(3) Upload your .mat file to Canvas. This is done by going to the Math 221 Canvas site, going to the Assign- ments page, and following the instructions there.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] C math matlab 221 MATLAB ASSIGNMENT 02
$25