Thursday, 21 December 2017

Wednesday, 20 December 2017

Monday, 4 September 2017

Introduction

The identity matrix is a the simplest nontrivial diagonal matrix, defined such that
1 x (X) = X

for all vectors x. An identity matrix may be denoted 1,I,E (the latter being an abbreviation for the German term "Einheitsmatrix"; Courant and Hilbert 1989, p. 7), or occasionally , with a subscript sometimes used to indicate the dimension of the matrix. Identity matrices are sometimes also known as unit matrices (Akivis and Goldberg 1972, p. 71).[1]
 I=[1 0 ... 0; 0 1 ... 0; | | ... |; 0 0 ... 1].



identity-matrix.png
Image Courtesy: wikipedia.org
Programs:
#include <stdio.h>
#define ID 15

int main(){
   int i,j;
   int identity=ID+1;
   int a[ID][ID];
   /*Loop until the user enter's the data correctly */
   while(identity>ID){
       printf("Enter the value for identity Matrix<%d:", ID);
       scanf("%d", &identity);
   }
   /*Input the value for identity matrix in array */
   for(i=0;i<identity;i++){
       for(j=0;j<identity;j++){
           /* if i=j then the value is always 1 in identity matrix */
           if(i==j){
               a[i][j]=1;
           }
           /* if i!=j then the value is always 0 in identity matrix */
           else{
               a[i][j]=0;
           }
       }
   }
   printf("\n");
   /* Print the entire identity matrix */
   for(i=0;i<identity;i++){
       printf("\t|");
       for(j=0;j<identity;j++){
           printf(" %d ", a[i][j]);
       }
       printf("|\n");
   }
}
Output:
Enter the value for identity Matrix<15:5

       | 1  0  0  0  0 |
       | 0  1  0  0  0 |
       | 0  0  1  0  0 |
       | 0  0  0  1  0 |
       | 0  0  0  0  1 |

Process returned 5 (0x5)   execution time : 4.578 s
Press any key to continue.

References:

  1. Akivis, M. A. and Goldberg, V. V. An Introduction to Linear Algebra and Tensors. New York: Dover, 1972.

  2. Ayres, F. Jr. Schaum's Outline of Theory and Problems of Matrices. New York: Schaum, p. 10, 1962.

  3. Courant, R. and Hilbert, D. Methods of Mathematical Physics, Vol. 1. New York: Wiley, 1989.

  4. Weisstein, Eric W. "Identity Matrix." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/IdentityMatrix.html

Cite this as:

Bhagchandani, Niraj. “Matrix Programs - P8 Unit/Identity Matrix in C Language.” Everything Data Structure in C Language, Blogger, 4 Sept. 2017, edatastructure.blogspot.in/2017/09/matrix-programs-p8-unitidentity-matrix.html.

About This article:

Sunday, 3 September 2017


Introduction

A zero matrix is an mxn matrix consisting of all 0s (MacDuffee 1943, p. 27), denoted 0. Zero matrices are sometimes also known as null matrices (Akivis and Goldberg 1972, p. 71).
null-matrix.png
Image Courtesy: wikimedia.org
#include <stdio.h>
#define COLS 15
#define ROWS 15

int main(){
   int columns=COLS+1,rows=COLS+1;
   int a[COLS][ROWS];
   int i,j;
   printf("\nNULL MATRIX PROGRAM");
   printf("\n===================");
   /*Take the number of columns from user as input*/
   while(columns>COLS){
       printf("\nEnter number of columns: ");
       scanf("%d", &columns);
   }
   /*Take the number of rows from user as input*/
   while(rows>ROWS){
       printf("\nEnter number of rows: ");
       scanf("%d", &rows);
    }
   /*Assign value 0 to all rows and columns in matrix and print them.*/
   for(i=0;i<rows;i++){
       for(j=0;j<columns;j++){
           a[i][j]=0;
           printf("\na[%d][%d]: %d", i,j, a[i][j]);
       }
   }
   printf("\nThe value for a[%d][%d] is: \n\n",columns,rows);
   /*Print the Matrix in proper format*/
   for(i=0;i<rows;i++){
       printf("\t| ");
       for(j=0;j<columns;j++){
           printf(" %d ", a[i][j]);
       }
       printf(" |\n");
   }
   return 0;
}


NULL MATRIX PROGRAM
===================
Enter number of columns: 3

Enter number of rows: 4

a[0][0]: 0
a[0][1]: 0
a[0][2]: 0
a[1][0]: 0
a[1][1]: 0
a[1][2]: 0
a[2][0]: 0
a[2][1]: 0
a[2][2]: 0
a[3][0]: 0
a[3][1]: 0
a[3][2]: 0
The value for a[3][4] is:

       |  0  0  0  |
       |  0  0  0  |
       |  0  0  0  |
       |  0  0  0  |

Process returned 0 (0x0)   execution time : 3.241 s
Press any key to continue.

References:

  1. Weisstein, Eric W. "Zero Matrix." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/ZeroMatrix.html
  2. Akivis, M. A. and Goldberg, V. V. An Introduction to Linear Algebra and Tensors. New York: Dover, 1972.
  3. MacDuffee, C. C. Vectors and Matrices. Washington, DC: Math. Assoc. Amer., 1943

Cite this as:

  • Bhagchandani, Niraj. “Matrix Programs - P7 Null Matrix in C Language.” Everything Data Structure in C Language, Blogger, 4 Sept. 2017, edatastructure.blogspot.in/2017/09/matrix-programs-null-matrix-in-c.html.

About This article: 

  1. Google Drive: Download Matrix Program - Null Matrix In  C Language

  2. Blog Post: Blog Link- Matrix Program - Null Matrix In  C Language