Professional Documents
Culture Documents
COURSE: CSE-AI
1.SOLUTION:
given,t:R^2 to R^2
T(x,y)=(x+y,x-2y)
a)V=[-3 -2],T(V) =
python code:
import numpy as np
def T(V):
W = np.zeros((2,1)) # Size of the output vector (2 X 1)
W[0,0] = 1*V[0,0]+1*V[1,0]
W[1,0] = 1*V[0,0]-2*V[1,0]
return W
# creating a 1-D list (Vertical)
list = [[-3],[-2]] # input vector
V = np.array(list)
W = T(V)
# showing input vector
print("Input Vector")
print(V)
# showing Output vector
print("Output Vector")
print(W)
Input Vector
[[-3]
[-2]]
Output Vector
[[-5.]
[ 1.]]
python code:
import numpy as np
def T(V):
W = np.zeros((2,1)) # Size of the output vector (2 X 1)
W[0,0] = 1*V[0,0]+1*V[1,0]
W[1,0] = 1*V[0,0]-2*V[1,0]
return W
# creating a 1-D list (Vertical)
list = [[-1],[5]] # input vector
V = np.array(list)
W = T(V)
# showing input vector
print("Input Vector")
print(V)
# showing Output vector
print("Output Vector")
print(W)
Input Vector
[[-1]
[ 5]]
Output Vector
[[ 4.]
[-11.]]
2. Write a Python program to find the orthonormal matrix from the following set of orthogonal vectors. V1 = [1,0,-1];V2 = [1,sqrt2,1] and v3=
[1,-sqrt2,1]
solution:
python code:
import numpy as np
# Define the orthogonal vectors
v1 = np.array([1, 0, -1])
v2 = np.array([1, np.sqrt(2), 1])
v3 = np.array([1, -np.sqrt(2), 1])
# Perform Gram-Schmidt process to obtain orthonormal vectors
u1 = v1 / np.linalg.norm(v1)
u2 = v2 - np.dot(v2, u1) * u1
u2 = u2 / np.linalg.norm(u2)
u3 = v3 - np.dot(v3, u1) * u1 - np.dot(v3, u2) * u2
u3 = u3 / np.linalg.norm(u3)
# Convert the orthonormal vectors into a matrix
orthonormal_matrix = np.vstack((u1, u2, u3))
# Output the orthonormal matrix
print("Orthonormal Matrix:")
print(orthonormal_matrix)
Orthonormal Matrix:
[[ 0.70710678 0. -0.70710678]
[ 0.5 0.70710678 0.5 ]
[ 0.5 -0.70710678 0.5 ]]
3. Write a Python program to check whether the following vectors are orthogonal or not?. If so, find the orthonormal vectors.v1= [3,1,1], v2=
[-1,2,1] and v3=[-1/2,-2,7/2]
SOLUTION:
PYTHON CODE:
import numpy as np
4. Write a Python program to find the orthonormal basis for the following set of vectors S = {(1,-1,1);(1,0,1);(1,1,2)}
SOLUTION:
Python code:
import numpy as np
Orthonormal basis:
[ 0.57735027 -0.57735027 0.57735027]
[0.40824829 0.81649658 0.40824829]
[-0.70710678 0. 0.70710678]
check 0s completed at 2:39 PM