<<

MATH 22AL Lab # 5

1 Objectives

In this LAB you will explore the following topics using MATLAB.

• Linear combination of vectors.

• Spanning of a

• Linearly independent set of vectors.

for a vector space.

Important: Do not Change the name of the Variables that you supposed to type in MATLAB, type as you are asked.

1 2 Recording and submitting your work

The following steps will help you to record your work and save and submit it successfully.

• Open a terminal window.

– In Computer LAB (2118 MSB) click on terminal Icon at the bottom of the screen – In Windows OS, Use Putty – In MAC OS, Use terminal window of MAC.

• Start a MATLAB Session that is :

– Type ”textmatlab” Press Enter

• Enter your information that is :

– Type ” diary LAB5.text” – Type ”% First Name:” then enter your first name – Type ”% Last Name:” then enter your Last name – Type ”% Date:” then enter the date – Type ”% Username:” then enter your Username for 22AL account

• Do the LAB that is :

– Follow the instruction of the LAB. – Type needed command in MATLAB. – All commands must be typed in front of MATLAB Command ” >> ”..

• Close MATLAB session Properly that is :

– When you are done or if you want to stop and continue later do the following: – Type ”save” Press Enter – Type ”diary off” Press Enter – Type ”exit” Press Enter

• Edit Your Work before submitting it that is :

– Use pico or editor of your choice to clean up the file you want to submit: – in command line of pine type ”pico LAB5.text” – Delete the errors or insert missed items. – Save using ”ˆ o= control key then o” – Exit using ”ˆ x= control key then x”

• Send your LAB that is :

– Type ”ssh point” : Press enter – Type submitm22al LAB2.text

2 3 Background Linear Combinations (Reading Materials)

Definition : n Let a1, a2, . . . an be scalars and v1, v2,... vn be vectors in R . the vector w = a1v1 +a2v2 +···+anvn, is called a Linear Combination of the vectors v1, v2,... vn.

EXAMPLE 1: Let v1 = (1, 2, 0), v2 = (0, −1, 2), then

w = 2v1 − 3v2 = 2(1, 2, 0) − 3(0, −1, 2) = (2, 7, −6)

So, w is linear combination of the vectors v1, v2. The vector equation 2(1, 2, 0) − 3(0, −1, 2) = (2, 7, −6) can be written as

 1   0   2  2  2  − 3  −1  =  7  0 2 −6 the left hand side can be represented as a multiplication,

 1 0   2   2  2 −1 = 7   −3   0 2 −6

    c1   v1 v2 = w c2

In General if a vector w is a linear combination of the vectors v1, v2,... vn then the vector equation

w = a1v1 + a2v2 + ··· + anvn can be expressed in matrix notation as   a1  a2   v v ... v    = w 1 2 n  .   .  an

  Note that the columns of the matrix v1 v2 ... vn are the vectors v1, v2,... vn.

3 EXAMPLE 2: Suppose you want to determine if a given vector w = (2, 7, −6) is a linear combi- nation of the vectors v1 = (1, 2, 0), and v2 = (0, −1, 2). This means find (if thy exist) scalars x1 and x2 so that x1v1 + x2v2 = w? Substitute for v1 and v2. We need to answer this question:

Can we find scalars x1 and x2 such that  1   0   2  x1  2  + x2  −1  =  7  0 2 −6

This is equivalent to solving the following linear system Ax = w:

 1 0   2   x  2 −1 1 = 7   x   0 2 2 −6 which represents the following system of linear equations:   1x1 + 0x2 = 2 2x1 + (−1)x2 = 7  0x1 + 2x2 = −6

Recall that a linear system AX = w is consistent (has a solution) if and only if rref(A) and rref([A| w]) have the same number of nonzero rows or ((A) = rank(([A| w]).

So to find out if w = (2, 7, −6) is a linear combination of the vectors v1 = (1, 2, 0), and v2 = (0, −1, 2), we need to determine the number of the non-zero rows of  1 0  rref  2 −1  0 2 and the augmented matrix

 1 0 2  rref  2 −1 7  0 2 −6

Recall The number of the non-zero rows of a matrix is called the rank of that matrix.

4 Using MATLAB: To determine if a given vector w is a linear combinations of the vectors v1, v2,... vn Use the following steps:

• Form matrix A whose columns are the vectors v1, v2,... vn you can do that by entering vectors

• Form the augmented matrix B = [A| w] ,

• Find rref(A) and rref(B)

• If number of number of non-zero rows two row reduced forms are the same then w

is a linear combination of vectors v1, v2,... vn. Otherwise it is not.

• This can be done in MATLAB by typing rank(A) and rank(B).

• So if rank(A) = rank(B) then w is a linear combinations of the vectors v1, v2,... vn. Otherwise, it is not.

End of reading Materials

5 Start Typing in MATLAB EXAMPLE 3: Use MATLAB to determine if w = (2, 7, −6) is a linear combination of the vectors v1 = (1, 2, 0), and v2 = (0, −1, 2). Step 1 : Type the following and press ”return” after each line: v1=[1 2 0]’ v2=[ 0 -1 2]’ w = [ 2 7 -6]’ A=[v1 v2] B= [A w] Step 2 : Type : rank(A) rank(B)

If the ranks are equal then w is a linear combination of the vectors v1, v2. EXAMPLE 4: Use MATLAB to express w = (2, 7, −6) as a linear combination of the vectors v1 = (1, 2, 0), and v2 = (0, −1, 2). type : rref(B) to solve the linear system AX = [w].

Use a pen and paper (and rref(B)) to find c1 and c2 such that w = c1v1 + c2v2. Enter your answers as: c1= Your answer c2 = Your answer.

Check your work by typing: w1= c1*v1 + c2*v2 Then type: tf = isequal(w,w1) If the answer is 1 they are equal if the answer is 0 they are not equal.

6 4 Spanning set of a vector space(Reading Materials)

Definition:

Let v1, v2,... vn be vectors in the vector space V . Let W be the set of all linear combina- tion of the vectors v1, v2,... vn. You can prove that W is a subspace of V . The subspace

W is called the space spanned by the vectors v1, v2,... vn. The set {v1, v2,... vn} is called a spanning set of W .

Note:

• You should be able to prove that W is a subspace of V by showing that W is closed under and multiplication.

• To show that the vector w is in the vector space spanned by the set of vectors

S = {v1, v2,... vn}? one needs to show that w is a linear combination of the vectors

v1, v2,... vn in S. As we did in Example 4 above.

n • To show that S = v1, v2,... vn span R we need to define A as A = [v1, v2,... vn], then find the rank(A). If rank(A) = n then S is a spanning set of Rn , otherwise n S = v1, v2,... vn does not span R . ( Why?)

(End of Reading Materials)

7 Start Typing in MATLAB Use MATLAB:

1.) Determine whether the vectors v1 = (1, 1, 2), v2 = (1, 0, 1) and v3 = (1, 1, 2), v2 = (2, 1, 3) span the vector space R3 Type: A1 = [1 1 2; 1 0 1; 1 1 2]0 You should have vectors in columns of the matrix. AR1= rref(A1) If you get an identity matrix, the vectors span R3. A1n= rank(A1) If the rank is 3 the vectors span R3. A1n= rank(AR1) If the rank is 3 the the vectors span R3. 2.) Determine whether the vectors b = (6, 11, 6) is in the spanning subspace of the vectors in the set S = v1 = (2, 1, 4), v2 = (1, −1, 3), v3 = (3, 2, 5). Type: A2= [ 2 1 4; 1 -1 3; 3 2 5]’ B2=[ 2 1 4; 1 -1 3; 3 2 5; 6 11 6]’ r1= rref(A2) r2= rref(B2) r3= rank(A2) r4= rank(B2)

If you decide that b = (6, 11, 6) is in spanning subspace of vectors in S, type: ANSA1= 1

Otherwise type: ANSA1= 0

8 5 Linearly independent vectors(Reading Materials)

Definition

Let S = {v1, v2,... vn} be a set of vectors in the vector space V . The set S is a linearly independent set if none of the vectors v1, v2,... vn is expressible as a linear combination of the other vectors in S. This is equivalent to the following:

• Vectors v1, v2,... vn are linearly independent if and only if the vector equation

x1v1 + x2v2 + ... + xnvn = 0

has only trivial solution. That is the only solution is x1 = x2 = ··· = xn = 0.

• Let A be tha matrix whose columns are vectors in S, so

A = [v1, v2,... vn]

 I  then S is linearly independent if and only if rref(A) looks like 0 • If S is a linealy independent set then the solution to AX = 0 is

x1 = 0 x2 = 0 . . .. . xn = 0

• A special case: If A is a . AX = 0 has only the trivial solution if and only if A is invertible if and only if det(A) 6= 0

• So the columns of a square matrix A are linearly independent only if det(A) 6= 0.

(End of Reading Materials)

9 Start Typing in MATLAB Use MATLAB:

1.) Determine if the vectors v1 = (2, −1, 2, 3), v2 = (1, 2, 5, −1), v3 = (7, −1, 5, 8) are linearly independent vectors in R4. Type: L1 = [2 − 1 2 3; 1 2 5 − 1; 7 − 1 5 8]0 LR1 = rref(L1)

If you decide that v1, v2, v3 are linearly independent type: ANSL1= 1 Otherwise type: ANSL1= 0

2.) Determine if the vectors v1 = (2, −1, 0, 3), v2 = (1, 2, 5, −1), v3 = (7, −1, 5, 8) are linearly independent vectors in R4. Type: L2 = [2 − 1 0 3; 1 2 5 − 1; 7 − 1 5 8]0 LR2 = rref(L2)

If you decide that v1, v2, v3 are linearly independent type: ANSL2= 1 Otherwise type: ANSL2= 0

3.) If the vectors in problem 2 above are linearly dependent, write v1 as linear combi- nation of two other vectors. Type: L3 = [2 − 1 0 3; 1 2 5 − 1; 7 − 1 5 8]0 LR3 = rref(L3)

Solve L3 X = 0 to get c1v1 + c2v2 + c3v3 = 0 then solve it for v1. (need pen and paper !!!! )

Your answer should look like v1 = av2 + bv3. If you calculated a and b, type: ANSa= [a] Enter the numerical value of a inside the bracket for a type: ANSb= [b] Enter the numerical value of b inside the bracket for b

10 6 BASIS (Reading Materials)

Definition A set of vectors in a vector space V form a basis for V if the set is linearly independent AND spans V . If you have a set on n vectors in an n− dimensional vector space V to determine if they form a basis for V put them in columns of a matrix BA. Matrix BA should be an n by n matrix. Find det(BA) if det(BA) 6= 0 then the columns of BA are linearly independent and they span the vector space V , that is they form a basis for V . Note:

• A set of three vectors in R4 can not form a basis for the 4-dimensional vector space R4. (Why?) You do not have to type your answer, review your book if you are not sure about the answer.

• A set of three vectors in R2 can not form a basis for the 2-dimensional vector space R2. (Why?) You do not have to type your answer, review your book if you are not sure about the answer.

(End of Reading Materials)

11 Start Typing in MATLAB Use MATLAB:

1.) Determine if the vectors v1 = (2, −1, 2, 3), v2 = (1, 2, 5, −1), v3 = (7, −1, 5, 8) form a basis for R4. Type: BA1 = [2 − 1 2 3; 1 2 5 − 1; 7 − 1 5 8]0 BAR1 = rref(BA1) 4 If you decide that v1, v2, v3 form a basis for R , type: ANBA1= 1 Otherwise type: ANBA1= 0

3 2.) Determine if the vectors v1 = (1, 2, 3), v2 = (2, 9, 0), v3 = (3, 3, 4) form a basis for R . Type: BA2 = [1 2 3; 2 9 0; 3 3 4]0 BAR2 = rref(BA2) 3 If you decide that v1, v2, v3 form a basis for R , type: ANBA2= 1 Otherwise type: ANBA2= 0

3 3.) Determine if the vectors v1 = (2, 4, 6), v2 = (2, 9, 0), v3 = (3, 3, 4) form a basis for R . Type: BA3 = [2 4 6; 2 9 0; 3 3 4]0 DBA3 = det(BA3) 3 If you decide that v1, v2, v3 form a basis for R , type: ANBA3= 1 Otherwise type: ANBA3= 0

12 Start Typing in MATLAB Use MATLAB:

7 EXERCISE:

Type the names as they are

I.Use MATLAB to determine whether w is in the span of the given vectors v1, v2,... vn

. If your answer is yes, write w as a linear combination of the vectors v1, v2,... vn and enter the coefficients as entries of the matrix as instructed:

1.)v 1 = (1, 2, 3, 4), v2 = (−1, 0, 1, 3), v3 = (0, 5, −6, 8) and w = (3, −6, 17, 11). ( Note you need enter the vectors in MATLAB as columns of a matrix EXM1.)

If you decided that w = c1v1 + c2v2 + ··· + cnvn type

EXA1=[c1 c2 ··· cn] Example: if w = 2v1 − 3v2 + 5v3 enter EX1 = [2 − 3 5]

2.)v 1 = (1, 2, 3, 4), v2 = (−1, 0, 1, 3), v3 = (0, 5, −6, 8) and w = (0, −6, 17, 11). ( Note you need enter the vectors in MATLAB as columns of a matrix EXM2.)

If you decided that w = c1v1 + c2v2 + ··· + cnvn type

EXA2=[c1 c2 ··· cn] Example: if w = 2v1 − 3v2 + 5v3 enter EX1 = [2 − 3 5]

3.)v 1 = (1, 2, 3, 4), v2 = (−1, 0, 1, 3), v3 = (0, 5, −6, 8), v4 = (1, 15, −12, 8) and w = (0, −6, 17, 11). ( Note you need enter the vectors in MATLAB as columns of a matrix EXM3.)

If you decided that w = c1v1 + c2v2 + ··· + cnvn type

EXA3=[c1 c2 ··· cn] Example: if w = 2v1 − 3v2 + 5v3 enter EX1 = [2 − 3 5]

4.)v 1 = (1, 2, 3, 4), v2 = (−1, 0, 1, 3), v3 = (0, 5, −6, 8), v4 = (0, −8, 16, −9) and w = (0, −6, 17, 11). ( Note you need enter the vectors in MATLAB as columns of a matrix EXM4.)

If you decided that w = c1v1 + c2v2 + ··· + cnvn type

EXA4=[c1 c2 ··· cn] Example: if w = 2v1 − 3v2 + 5v3 enter EX1 = [2 − 3 5]

13 Start Typing in MATLAB Use MATLAB:

8 EXERCISE:

Type the names as they are 5.) Let EXRA15 be a random 4 x 6 matrix. (Type EXRA5= round(10*rand(4,6) )) a.) The columns of EXRA5 are vectors in R4. Do they form a basis for R4? If you decided that the columns of EXRA5 form a basis for R4 type EXA5a=1 otherwise type EXA5a=0

b.) The columns of EXRA5 are vectors in R4. Are they linearly independent vectors in R4? If you decided that the columns of EXRA5 are linearly independent vectors in R4 type EXA5b=1 otherwise type EXA5b=0

c.) The columns of EXRA5 are vectors in R4. Do they span R4?) If you decided that the columns of EXRA5 span R4 type EXA5c=1 otherwise type EXA5c=0

This last part is only for your own practice you do not have to report on this part. 6. ) Do the same test in problem 5 above, on a 4 x 2 matrix and a 4 x 4 matrix. See if you can decide and answer the questions in parts a, b and c of the problem above, about this matrix. 7.) Now try the same test on random matrix of size 6 x 7, 6 x 1, and 6 x 6. 8.) How many vectors do you think you need to make a basis for a n-dim space. 9.) What seems to happen if you have less vectors than the of the vector space? 10.) What seems to happen if you have more vectors than the dimension of the vector space?

14