0% found this document useful (0 votes)
14 views2 pages

rajakumaran maths python assignment

This document contains a Python assignment for a mathematics course, focusing on various linear algebra concepts. It includes code snippets for checking linear independence, spanning R³, reduced row echelon form, angles between vectors, orthonormal basis using Gram-Schmidt, linear transformations, singular value decomposition, diagonalization, solving systems using Gaussian elimination, and finding inverses using Gauss-Jordan. Each section provides a brief explanation and corresponding Python code to demonstrate the concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

rajakumaran maths python assignment

This document contains a Python assignment for a mathematics course, focusing on various linear algebra concepts. It includes code snippets for checking linear independence, spanning R³, reduced row echelon form, angles between vectors, orthonormal basis using Gram-Schmidt, linear transformations, singular value decomposition, diagonalization, solving systems using Gaussian elimination, and finding inverses using Gauss-Jordan. Each section provides a brief explanation and corresponding Python code to demonstrate the concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

NAME:R.

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")

2. Check if Vectors Span R³

# Same idea, check if rank is 3


vectors = [[1, 0, 2], [0, 1, 1], [1, 1, 3]]
A = Matrix(vectors).T
print("Spans R3:" if A.rank() == 3 else "Does NOT Span R3")

3. Reduced Row Echelon Form and Basis

A = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])


rref, pivots = A.rref()
print("RREF:\n", rref)
print("Row Space Basis:", A.rowspace())
print("Column Space Basis:", A.columnspace())
print("Null Space Basis:", A.nullspace())

4. Angle Between Vectors

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)

5. Orthonormal Basis using Gram-Schmidt

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

vectors = [np.array([1, 1, 0]), np.array([1, 0, 1])]


orthonormal = gram_schmidt(vectors)
print("Orthonormal Basis:", orthonormal)

6. Matrix of Linear Transformation w.r.t. Basis

You'll need to define the transformation and bases. Here's a skeleton:


B = [Matrix([2, 1]), Matrix([-1, 1])]
U = [Matrix([1, 1, 1]), Matrix([1, 1, -1]), Matrix([1, 0, 1])]

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))

7. Singular Value Decomposition (SVD)

from numpy.linalg import svd

A = np.array([[1, 2], [3, 4], [5, 6]])


U, S, VT = svd(A)
print("U:\n", U)
print("S:\n", S)
print("VT:\n", VT)

8. Diagonalize Matrix

from sympy import Matrix

A = Matrix([[1.5, 0.5, -2.5], [0.5, 2.5, -0.5], [-2.5, -0.5, 5.5]])


P, D = A.diagonalize()
print("Diagonal Matrix D:\n", D)
print("Matrix P (eigenvectors):\n", P)

9. Solve System using Gaussian Elimination

A = Matrix([[1, -1, 3, 0], [2, -1, 4, 3], [1, 1, 1, 3]])


rref, pivots = A.rref()
print("Solution from RREF:\n", rref)

10. Inverse using Gauss-Jordan

A = Matrix([[1.5, 0.5, -2.5], [0.5, 2.5, -0.5], [-2.5, -0.5, 5.5]])


A_inv = A.inv(method='GE')
print("Inverse Matrix:\n", A_inv)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy