Professional Documents
Culture Documents
Algebra For Ai Miscellaneous Code Snippets
Algebra For Ai Miscellaneous Code Snippets
Algebra For Ai Miscellaneous Code Snippets
CB.SC.U4AIE23104
1.
import numpy as np
print(matrix)
2.
import numpy as np
# Define a diagonal matrix with two non-zero elements and one zero element
diagonal_elements = [1, 2, 0] # One eigenvalue is zero
print(matrix)
3.
import numpy as np
print(matrix)
4.
import numpy as np
CB.SC.U4AIE23104 1
ML BOOTCAMP ASSIGNMENT
CB.SC.U4AIE23104
# Stack the vectors vertically to form a matrix
matrix = np.vstack((v1, v2))
print(matrix)
5.
import numpy as np
def construct_matrix(t):
column_space_vector = np.array([1, 1, 1])
nullspace_vector = np.array([1, 1, 1, 1])
return matrix
# Example usage
t_value = 2
result_matrix = construct_matrix(t_value)
print("Matrix:")
print(result_matrix)
6.
import numpy as np
def construct_matrix():
nullspace_vector = np.array([4, 3, 2, 1])
# Transpose the vector to make it a row vector
matrix = nullspace_vector.reshape(1, -1)
return matrix
CB.SC.U4AIE23104 2
ML BOOTCAMP ASSIGNMENT
CB.SC.U4AIE23104
# Example usage
result_matrix = construct_matrix()
print("Matrix:")
print(result_matrix)
7.
import numpy as np
8.
import numpy as np
CB.SC.U4AIE23104 3
ML BOOTCAMP ASSIGNMENT
CB.SC.U4AIE23104
9.
import numpy as np
if rank_A == rank_augmented:
print("Error: b is in the column space of A. Choose a different b.")
else:
print("The system Ax = b, where b is not in the column space of A, is:")
print("A:")
print(A)
print("b:")
print(b)
10.
% Extract bases for column space, left null space, row space, and right null space
A = U(:, 1:r); % Basis for column space
B = U(:, r+1:end); % Basis for left null space
C = V(:, 1:r); % Basis for row space
D = V(:, r+1:end); % Basis for right null space
CB.SC.U4AIE23104 4
ML BOOTCAMP ASSIGNMENT
CB.SC.U4AIE23104
% Display projection matrices
disp('Projection matrix for projecting into column space:');
disp(Prc);
disp('Projection matrix for projecting into left null space:');
disp(Prln);
disp('Projection matrix for projecting into row space:');
disp(Prr);
disp('Projection matrix for projecting into right null space:');
disp(Prrn);
11.
% Given matrix X
X = [39, 42, 39, 34, 29;
23, 24, 22, 23, 18;
28, 24, 20, 28, 18;
34, 32, 28, 36, 25;
10, 10, 9, 9, 7];
% Vector y
y = [1, 2, 3, 4, 5]';
% Extract bases for column space, left null space, row space, and right null space
A = U(:, 1:r); % Basis for column space
B = U(:, r+1:end); % Basis for left null space
C = V(:, 1:r); % Basis for row space
D = V(:, r+1:end); % Basis for right null space
CB.SC.U4AIE23104 5
ML BOOTCAMP ASSIGNMENT
CB.SC.U4AIE23104
disp('Projection onto row space:');
disp(y_proj_row_space);
disp('Projection onto right null space:');
disp(y_proj_right_null_space);
12 .
% Given matrix X
X = [23, 41, 50, 50;
11, 21, 25, 24;
17, 25, 33, 37;
13, 23, 29, 30;
22, 36, 46, 49];
% Vectors y1 and y2
y1 = [1, 2, 3, 4, 5]';
y2 = [4, 3, 2, 1]';
% Extract bases for column space, left null space, row space, and right null space
A = U(:, 1:r); % Basis for column space
B = U(:, r+1:end); % Basis for left null space
C = V(:, 1:r); % Basis for row space
D = V(:, r+1:end); % Basis for right null space
CB.SC.U4AIE23104 6
ML BOOTCAMP ASSIGNMENT
CB.SC.U4AIE23104
disp(y1_proj_left_null_space);
disp('Projection of y1 onto row space:');
disp(y1_proj_row_space);
disp('Projection of y1 onto right null space:');
disp(y1_proj_right_null_space);
CB.SC.U4AIE23104 7