Tutorial: Use MATLAB to Determine Linear Independence of Sets of Vectors

Tutorial: Use MATLAB to Determine Linear Independence of Sets of Vectors

MATLAB Exercise # 2 Tutorial & Assignment. Tutorial: Use MATLAB to determine Linear Independence of sets of vectors. (a.) Create a MATLAB "m-file" ("function" file) that accepts as input a matrix "B" and returns a scalar "d" that equals "1" if the vector if the columns of "B" are Linearly Independent and "0" if the columns of "B" are Linearly Dependent. Here is such a file. %This program determines whether a set of column vectors is linearly independent %or linearly dependent. It accepts a Matrix %"B" and returns a scalar "d" which equals "1" if %the columns of "A" are Linearly Independent and "0" if they are %Linearly Dependent. function [d]=Dependence(B) C=rref(B); m=length(diag(B(:,1))); n=length(B(1,:)); if n>m d=0; else s=sum(diag(C)); if n>s d=0; else d=1; end end Page 1 of 5 (b.) Create a MATLAB "m-file" ("function" file) that has the following features. It contains a 4X2 matrix, "A42" with Linearly Independent columns and two 4x1 vectors. One of those two vectors, namely:"X4" does not lie in the "plane" determined by the column vectors of "A42". The other, namely:"y4" does lie in that plane. The file also contains a 3x2 matrix, "A32", and two 3X1 vectors one of which lies in the plane formed by the columns of "A32" while the other does not. A 2X2 matrix is also contained in the file along with two 2x1 vectors. When the file is "Run" it calls the other m-file named "Dependence" and displays matrices "A42","A32", and "A22" augmented with each of the appropriate given vectors along with a message citing whether the augmented matrix posseses Linearly Independent or Linearly Dependent columns. This is a file that achieves that functionality. Page 2 of 5 %This file "calls" the m-file titled "Dependence" and %uses the results of that file to determine if a set %of column vectors formed by augmenting a matrix results %in a set of column vectors that is Linearly Independent or %Linearly Dependent. A42=[1 9;3 11;7 13;5 15]; A32=[1 5;3 2;7 4]; A23=[1 3;5 2]; x4=[6;5;11;17]; y4=[10;14;20;20]; x3=[9;7;11]; y3=[11;7;15]; x2=[-1;1]; y2=[-2;3]; R={}; R{1,1}=[A42 x4]; R{1,2}=[A42 y4]; R{1,3}=[A32 x3]; R{1,4}=[A32 y3]; R{1,5}=[A23 x2]; R{1,6}=[A23 y2]; R{2,1}=['Set is Linearly Independent';'Set is Linearly Dependent ']; for k=1:1:6; fhandle=@Dependence; [d]=Dependence(R{1,k}); if d==0 display(R{1,k}) display(R{2,1}(2,:)) elseif d==1 display(R{1,k}) display(R{2,1}(1,:)) end end If this file is "Run", here are the results. Page 3 of 5 ans = 1 9 6 3 11 5 7 13 11 5 15 17 Set is Linearly Independent ans = 1 9 10 3 11 14 7 13 20 5 15 20 Set is Linearly Dependent ans = 1 5 9 3 2 7 7 4 11 Set is Linearly Independent ans = 1 5 11 3 2 7 7 4 15 Set is Linearly Dependent ans = 1 3 -1 5 2 1 Set is Linearly Dependent ans = 1 3 -2 5 2 3 Set is Linearly Dependent Page 4 of 5 Assignment: (a.) Create two m-files using those that I provided above as templates. You will use different matrices, namely: ⎛2 7 4 ⎞ ⎜ ⎟ 3 2 5 ⎛1 4 ⎞ ⎜ ⎟ ⎜ ⎟ ⎛1 −2 ⎞ A53 = ⎜4 5 6 ⎟, A32 = ⎜2 −2 ⎟, and A22 = ⎜ ⎟ and different ⎝1 1 ⎠ ⎜5 6 7 ⎟ ⎜1 3 ⎟ ⎜ ⎟ ⎝ ⎠ ⎝6 7 8 ⎠ ⎛ 6 ⎞ ⎛ 6 ⎞ ⎜ 8 ⎟ ⎜ 8 ⎟ 7 7 ⎜ ⎟ ⎜ ⎟ ⎜⎛ ⎟⎞ ⎜⎛ ⎟⎞ vectors, namely:x5 = ⎜10 ⎟, y5 = ⎜10 ⎟, x3 = ⎜4 ⎟, y3 = ⎜6 ⎟, and ⎜12 ⎟ ⎜12 ⎟ ⎜6 ⎟ ⎜1 ⎟ ⎜ ⎟ ⎜ ⎟ ⎝ ⎠ ⎝ ⎠ ⎝ 1 ⎠ ⎝14 ⎠ ⎛3 ⎞ x2 = ⎜ ⎟. Then you will "Run" your program as I did. You will submit ⎝6 ⎠ your 2 m-files along with the results in the "Command" window. (b.) For the Linearly Dependent sets that you found from part (a.), express the given vector as a linear combination of the columns of the corresponding matrix. Page 5 of 5 .

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    5 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us