C++ Program to Find Basis and Dimension of a Matrix

This is a C++ program to find Basis and Dimension of a Matrix.

Algorithm

Begin
   Function determinant() :
   It calculates determinant of the matrix.
   /*
      Arguments:
      n = number of elements.
      matrix[10][10] = input matrix.
   */
   declare the submatrix submatrix[10][10].
   //Body of the function:
   if (n == 2)
      return ((matrix[0][0] * matrix[1][1]) - (matrix[1][0] * matrix[0][1]))
   else
      Make a for loop c = 0 to n-1
         Declare and initialize submati = 0, submatj.
         Make a For loop i = 1 to n-1
         initialize subj = 0
         Make a For loop i = 1 to n-1
            if (j == c)
               continue
            submatrix[submati][submatj] = matrix[i][j].
            Increment subj.
         increment submati.
      Compute d = d + (pow(-1, c) * matrix[0][c] * determinant(n- 1, submatrix)).
End

Example

#include
#include
using namespace std;
double d = 0;
double determinant(int n, double matrix[10][10]) {
   double submatrix[10][10];
   if (n == 2)
      return ((matrix[0][0] * matrix[1][1]) - (matrix[1][0] *
      matrix[0][1]));
   else {
      for (int c = 0; c > n;
   double matrix[10][10];
   cout > matrix[j][i];
      }
   }
   d = determinant(n, matrix); //call the function
   if (d != 0)
      cout 

Output - 1

Enter the number of elements:
3 Enter elements one by one:
7 6 1
2 3 4
5 8 9
The elements form the basis of R3 as the determinant is
non-zero

Output - 2

Enter the number of elements:
4 Enter the elements one by one:
7 6 1 4
2 3 5 4
9 8 2 3
2 1 3 0
The elements don't form the basis of R4 as the
determinant is zero
Updated on: 2019-07-30T22:30:25+05:30

285 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements