rajakumaran maths python assignment
rajakumaran maths python assignment
RAJAKUMARAN
REG.NO:2403917710421071
CSE-A(II-SEM)
MATHS PYTHON ASSIGNMENT
1. Check Linear Independence
import numpy as np
from sympy import Matrix
# Example: Replace with your actual vectors
vectors = [[1, 2, 3], [2, 4, 6], [1, 0, 1]]
A = Matrix(vectors).T
print("Linearly Independent:" if A.rank() ==len(vectors) else "Linearly Dependent")
import numpy as np
from numpy.linalg import norm
from math import acos, degrees
v1 = np.array([1, 2, 3])
v2 = np.array([4, 5, 6])
cos_theta = np.dot(v1, v2) / (norm(v1) * norm(v2))
angle = degrees(acos(cos_theta))
print("Angle in degrees:", angle)
def gram_schmidt(vectors):
ortho = []
for v in vectors:
for u in ortho:
v -= np.dot(v, u) * u
if np.linalg.norm(v) > 1e-10:
ortho.append(v / np.linalg.norm(v))
return ortho
def transform(x):
x1, x2 = x
return Matrix([x1 - 2 * x2, 2 * x1 + x2, x1 + x2])
matrix = []
for b in B:
matrix.append(transform(b))
print("Transformation Matrix:\n", Matrix.hstack(*matrix))
8. Diagonalize Matrix