{"id":7062,"date":"2021-09-30T16:30:14","date_gmt":"2021-09-30T11:00:14","guid":{"rendered":"https:\/\/python-programs.com\/?p=7062"},"modified":"2021-11-22T18:39:24","modified_gmt":"2021-11-22T13:09:24","slug":"program-to-subtract-two-matrices","status":"publish","type":"post","link":"https:\/\/python-programs.com\/program-to-subtract-two-matrices\/","title":{"rendered":"Program to Subtract two Matrices in Python & C++ Programming"},"content":{"rendered":"

What is a matrix:<\/strong><\/p>\n

A matrix is a rectangular sequence of numbers divided into columns and rows. A matrix element or entry is a number that appears in a matrix.<\/p>\n

Example:<\/strong><\/p>\n

\"\"<\/p>\n

Above is the matrix which contains 5 rows and 4 columns and having elements from 1 to 20.<\/p>\n

In this order, the dimensions of a matrix indicate the number of rows and columns.<\/p>\n

Here as there are 5 rows and 4 columns it is called as 5*4 matrix.<\/p>\n

What is matrix subtraction:<\/strong><\/p>\n

Given two matrices of same order(dimensions) then we can easily add the two matrices by doing the difference of corresponding elements in both the matrices.<\/p>\n

Example:<\/strong><\/p>\n

\"\"<\/p>\n

 <\/p>\n

Here Matrix C is matrix subtraction\u00a0 of the matrices A and B.<\/p>\n

Examples for matrix addition:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Matrix 1  =    2    3   1\r\n                      1    2   3\r\n                     -3   0   2    \r\nMatrix 2 =      1    4    2\r\n                     -4    5   -1\r\n                      2    1     4<\/pre>\n

Output:<\/strong><\/p>\n

Printing the difference of matrices : \r\n1 -1 -1\r\n5 -3 4\r\n-5 -1 -2<\/pre>\n

Explanation:<\/strong><\/p>\n

 Here we subtracted the corresponding elements in both matrices<\/pre>\n

Program for Matrix Subtraction<\/h2>\n