Linear Algebra: Practice Programs in Python and C Languages : Linear Algebra: Linear Transformation and Diagonalization: Computation of Null Space and Range of a Matrix by Using Python
Linear Algebra
PROGRAMMES
IN PYTHON AND C LANGUAGES
UNIT − II:
LINEAR TRANSFORMATION AND DIAGONALIZATION
COMPUTATION OF NULL
SPACE AND RANGE OF A MATRIX BY USING PYTHON
The
null space (or kernel) of a matrix A is the set of all vectors x such that
Ax=0. The range (or column space) of a matrix A is the set of all possible
linear combinations of the columns of A. In Python, these can be computed using
libraries like NumPy and SymPy.
The
sympy library provides a direct function to compute the null space.
Python
from sympy import matrix
# Define your matrix
A_list = [[1,2,0],
[2,4,0],
[3,6,1]
A = Matrix (A list)
# Compute the null space
null_space_basis = A.nullspace ()
print ("Null Space Basis: ")
for vector in null_space_basis:
print (vector)
# You can verify by multiplying A with a vector from the null
space
# For example, if null_space_basis is not empty, take the first
vector
If null_space_basis:
null_vector = null_space_basis [0]
print ("\nVerification (A * null_vector):")
print (A * null vector)
NumPy's
scipy.linalg.null_space function, which relies on Singular Value Decomposition
(SVD), can also be used.
Python
import numpy as np
from scipy.linalg import null_space
# Define your matrix
A_np = np.array([1, 2,0],
[2, 4, 0],
[3, 6, 1]])
# Compute the null space
null_space_basis_np = null space (A_np)
print ("Null Space Basis (NumPy): ")
print (null space_basis_np)
# Verification
print("\nVerification (A * null_space_basis_np):")
print (A_np @ null_space_basis_np)
The
rank space can be found by identifying the linearly independent columns of the
matrix. This can be done by finding the basis for the column space.
Python
import numpy as np
# Define your matrix
A range = np.array([1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
# Using SVD to find a basis for the column space U, S, Vh = np.linalg.svd
(A_range)
#The first 'rank' columns of U form an orthornormal basis for
the column space
rank = np.linalg.matrix_rank (A_range)
range basis svd = U[:, :rank]
print ("Range Space Basis (SVD):")
print (range_basis_svd)
Linear Algebra: Practice Programs in Python and C Languages : Tag: maths, mathematics : - Computation of Null Space and Range of a Matrix by Using Python (Linear Algebra: Linear Transformation and Diagonalization)
Linear Algebra
MA25C02 2nd Semester | 2025 Regulation
English Essentials II
EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Tamils and Technology தமிழர்களும் தொழில்நுட்பமும்
UC25H02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Linear Algebra
MA25C02 2nd Semester | 2025 Regulation
Transforms and its Applications
MA25C03 2nd Semester EEE Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Applied Physics (CE) II
PH25C02 2nd Semester Civil, Agri Depts | 2025 Regulation | 2nd Semester 2025 Regulation
Applied Physics (CSIE) II
PH25C03 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Applied Physics (EE) II
PH25C04 2nd Semester EEE Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Applied Physics (ME) II
PH25C05 2nd Semester Mechanical Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Applied Chemistry (CE) II
CY25C02 2nd Semester Civil Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Applied Chemistry (ME) II
CY25C03 2nd Semester Mechanical Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Electron Devices
EC25C01 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Digital Principles and Computer Organization
CS25C06 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Electrical and Electronics Engineering
EE25C01 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Civil and Mechanical Engineering
GE25C01 2nd Semester EEE Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Data Structures using CPlusPlus
CS25C05 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Engineering Drawing
ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation
Data Structures and Algorithms
CS25C04 2nd Semester EEE Dept | 2025 Regulation
Circuits and Network Analysis
EC25C02 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Engineering Mechanics
ME25C02 2nd Semester Mech, Civil, Agri Depts | 2025 Regulation | 2nd Semester 2025 Regulation
Object Oriented Programming (OOPs)
CS25C07 2nd Semester CSE, CSE(CY) Depts | 2025 Regulation | 2nd Semester 2025 Regulation