Linear Algebra: Practice Programs in Python and C Languages

Computation of Dimension of Subspaces by Using C (Linear Algebra: Vector Spaces)

Linear Algebra: Practice Programs in Python and C Languages - Linear Algebra: Vector Spaces: Computation of Dimension of Subspaces by Using C

Linear Algebra

PROGRAMMES IN PYTHON AND C LANGUAGES

UNIT − 1: VECTOR SPACES

 

COMPUTATION OF DIMENSION OF SUBSPACES BY USING C

The dimension of a subspace is defined as the number of vectors in any of its bases. To compute the dimension of a subspace using C, one can implement algorithms to find a basis for the subspace and then count the number of vectors in that basis. This typically involves concepts from linear algebra, such as linear independence and spanning sets.

 

Steps to compute the dimension of a subspace in C:

• Represent the vectors: Represent vectors as arrays of floating−point numbers (e.g., float[] or double[]).

• Form a matrix: If the subspace is defined by a set of spanning vectors, arrange these vectors as rows or columns of a matrix.

• Perform Gaussian elimination (or similar row reduction): Apply row operations to the matrix to bring it into Row Echelon Form (REF) or Reduced Row Echelon Form (RREF). This process helps identify linearly independent vectors.

• Count pivot columns/rows: The number of non−zero rows in the REF (or the number of pivot columns) corresponds to the rank of the matrix. This rank is equal to the dimension of the column space (or row space), which is the dimension of the subspace spanned by the original vectors.


Example C implementation (conceptual outline)

C

#include <stdio.h>

#include <stdlib.h>

// Function to perform Gaussian elimination on a matrix

int gaussian Elimination (double **matrix, int rows, int cols)

{

int rank = 0;

int pivot_col = 0;

for (int i = 0; i < rows && pivot_col < cols; ++i, ++pivot_col)

{

Find pivot row

pivot_row = k;

}

}

// Swap rows if necessary

If (pivot_row !=i)

{

      double *temp = matrix[1];

      matrix [1] = matrix [pivot_row];

      matrix [pivot_row] = temp;

}

//If pivot element is zero, move to next column

If (matrix [i] [pivot_col] == 0) {

 i−−; // Re−process current row with next column continue;

// } Eliminate other rows

for (int k = 0; k < rows; ++k)

{

if (k !=i) {

double factor = matrix[k] [pivot_col] / matrix[i] [pivot_col];

for (int j=1 pivot_col; j < cols; ++j)

{

   matrix[k] [j] ‒= factor*  matrix[i][j];

}

}

}

rank++;

}

return rank;

}

int main() {

//Example: Subspace spanned by vectors {{1, 2,3}, {4, 5, 6},{7, 8, 9} }

int num vectors =3;

int vector_dim = 3;

// Dynamically allocate matrix

double **vectors = (double **) malloc (num vectors * sizeof(double * ) );

for (int i =0; i < num vectors; ++i)

{

    vectors[i] = (double *) malloc (vector_dim * sizeof(double));

}

// Initialize vectors (example data)

vectors [0][0] = 1; vectors [0] [1] = 2; vectors [0] [2] = 3;

int dimension = gaussianElimination (vectors, num_vectors, vector dim);

printf("Dimension of the subspace: %d\n", dimension);

//Free dynamically allocated memory

for (int i=0; i=0; i < num vectors; ++i) {

    free (vectors [i]);

}

free (vectors);

return 0;

}

 

Linear Algebra: Practice Programs in Python and C Languages : Tag: maths, mathematics : - Computation of Dimension of Subspaces by Using C (Linear Algebra: Vector Spaces)


Linear Algebra: Practice Programs in Python and C Languages



Under Subject


Linear Algebra

MA25C02 2nd Semester | 2025 Regulation



Related Subjects


English Essentials II

EN25C02 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