0% found this document useful (0 votes)
38 views3 pages

MATLAB Code for Linear Algebra Concepts

Uploaded by

navleenschool
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views3 pages

MATLAB Code for Linear Algebra Concepts

Uploaded by

navleenschool
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

MATH 232 – Computing Assignment #3 – MATLAB Code

Question 1: Fundamental subspaces of A

A = [1 1 1 1 5;
2 3 1 2 11;
1 1 1 3 7;
1 2 0 -1 4];

1(a) rref, column space, row space, null spaces

[R, piv] = rref(A)


basis_ColA = A(:, piv)

basis_RowA = R(1:3, :)

N = null(A,'r')
NAT = null(A','r')

1(b) rank–nullity

rankA = rank(A)
nullA_dim = size(N,2)
rankAT = rank(A')
nullAT_dim = size(NAT,2)

1(c) orthogonality checks

for i = 1:size(basis_ColA,2)
dot_col = dot(basis_ColA(:,i), NAT(:,1))
end

% Check that each row-space basis vector is orthogonal to each Null(A) vector
for j = 1:size(basis_RowA,1)
for k = 1:size(N,2)
dot_row = basis_RowA(j,:) * N(:,k)
end
end
Question 2: Change of basis and linear map

% Basis vectors
v1 = [0; 1; 2; 1];
v2 = [1; 5; 0; 1];
v3 = [2; 3; 6; 4];
v4 = [1; 3; -1; -1];

B = [v1 v2 v3 v4];

2(a) Change-of-basis matrix P_{B<-S} and coordinates of x

PB_S = inv(B)

x = [1; 2; 3; 4];
xB = PB_S * x % [x]_B

2(b) Matrix of L in basis B and [L(x)]_B

% L(x1,x2,x3,x4) = (x2 + 5x4, x1 - x3, x1 + x2 + x3 + x4, 0)

L = @(v)[v(2) + 5*v(4);
v(1) - v(3);
v(1) + v(2) + v(3) + v(4);
0];

Lv1 = L(v1);
Lv2 = L(v2);
Lv3 = L(v3);
Lv4 = L(v4);

% Express L(vj) in basis B: solve B * c = L(vj)


c1 = B \ Lv1;
c2 = B \ Lv2;
c3 = B \ Lv3;
c4 = B \ Lv4;

LB = [c1 c2 c3 c4]
LxB = LB * xB

You might also like