Linear Algebra: Practice Programs in Python and C Languages: Linear Algebra: Vector Spaces: Computation of Linear Dependence and Independence by Using Python
Linear Algebra
PROGRAMMES
IN PYTHON AND C LANGUAGES
UNIT − 1:
VECTOR SPACES
COMPUTATION OF LINEAR
DEPENDENCE AND INDEPENDENCE BY USING PYTHON
To
determine linear dependence or independence of a set of vectors Python, the
numpy library is used, specifically numpy.lina1g.matrix_rank function.
Method
• Represent vectors as
a matrix: Create a matrix where each column (or row)
represents one of the vectors in the set.
• Calculate the rank:
Use numpy.linalg.matrix_rank() to find the rank of this matrix.
•
Compare rank to the number of vectors:
•
If the rank of the matrix is equal to the number of vectors, the vectors are
linearly independent.
•
If the rank of the matrix is less than the number of vectors, the vectors are
linearly dependent.
Example
Python
import numpy as np
# Define a set of vectors
v1 = np.array([1, 2, 3])
v2 = np.array([4,5, 6])
v2 = np.array (7, 8, 9]) # This is linearly dependent on v1 and
v2: v3 = 2*v2 ‒ v1
# Create a matrix where vectors are columnsby matrix_dependent =
np.colum_stack ((v1, v2, v3))
# Calculate the rank of the matrix rank_dependent =
np.linalg.matrix_rank (matrix_dependent)
print (f"Matrix for dependent vectors: \n {matrix_dependent}")
print (f"Rank for dependent vectors:
(rank_dependent}")
if rank_dependent == matrix_dependent.shape[1]:
print ("vectors are linearl independent.")
else:
print ("vectors are linearly dependent,")
Print ("vectors are linearly dependent, ")
print("−" * 30)
#Define a set of Linearly independent vectors
V4 = np.array([1, 0, 0])
v5 = np.array([0, 1, 0])
v6 = np.array([0, 0, 1])
# Create a matrix where vectors are columns
matrix_independent = np.column_stack #
(v4, v5, v6))
# Calculate the rank of the matrix
rank_independent = np.linalg.matrix_rank
(matrix_independent)
print (f"Matrix for independent.
vectors: \n {matrix_ independent)")
print (f"Rank for independent vectors:
{rank_independent)")
if rank independent == matrix_independent. shape [1]:
print ("vectors are linearly independent.")
else:
print ("vectors are linearly dependent.")
Linear Algebra: Practice Programs in Python and C Languages : Tag: maths, mathematics : - Computation of Linear Dependence and Independence by Using Python (Linear Algebra: Vector Spaces)
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