Due to the lapse in federal government funding, NASA is not updating this website. We sincerely regret this inconvenience.
NASA Logo
Ocean Color Science Software

ocssw V2022
Matrix.h
Go to the documentation of this file.
1 #include <iostream>
2 
3 float** initializeMatrix(int n) {
4  float** temp = new float*[n];
5  for (int i = 0; i < n; i++)
6  temp[i] = new float[n];
7  return temp;
8 }
9 
10 void input(float** M, int n) {
11  std::cout << "Enter matrix: " << std::endl;
12  for (int i = 0; i < n; i++)
13  for (int j = 0; j < n; j++)
14  std::cin >> M[i][j];
15  std::cout << std::endl;
16 }
17 
18 void printMatrix(float** M, int n) {
19  for (int i = 0; i < n; i++) {
20  for (int j = 0; j < n; j++)
21  std::cout << M[i][j] << " ";
22  std::cout << std::endl;
23  }
24  std::cout << std::endl;
25 }
26 
27 float** add(float** M1, float** M2, int n) {
28  float** temp = initializeMatrix(n);
29  for (int i = 0; i < n; i++)
30  for (int j = 0; j < n; j++)
31  temp[i][j] = M1[i][j] + M2[i][j];
32  return temp;
33 }
34 
35 float** subtract(float** M1, float** M2, int n) {
36  float** temp = initializeMatrix(n);
37  for (int i = 0; i < n; i++)
38  for (int j = 0; j < n; j++)
39  temp[i][j] = M1[i][j] - M2[i][j];
40  return temp;
41 }
int j
Definition: decode_rs.h:73
void input(float **M, int n)
Definition: Matrix.h:10
float ** subtract(float **M1, float **M2, int n)
Definition: Matrix.h:35
void printMatrix(float **M, int n)
Definition: Matrix.h:18
float ** add(float **M1, float **M2, int n)
Definition: Matrix.h:27
float ** initializeMatrix(int n)
Definition: Matrix.h:3
int M[]
Definition: Usds.c:107
int i
Definition: decode_rs.h:71