ganselo
15-01-2009, 16:26
Дана матрица n*m
#include <iostream>
#include <iomanip>
using namespace std;
template<class type>
void add(type *array[], int nRow, int nCol);
template<class type>
void print(type *array[], const int nRow, const int nCol);
int main()
{
int nRow, nCol;
cout << "Input nRow: ";
cin >> nRow;
cout << "Input nCol: ";
cin >> nCol;
int *a[nCol], *b[nCol];
add(a, nRow, nCol);
add(b, nRow, nCol);
print(a, nRow, nCol);
for(unsigned i = 0; i < nRow; i++)
b[i][0] = a[i][0]; //Первый столбец новой матрицы идентичен первому
//столбцу исходной
for(unsigned i = 0; i < nRow; i++)
{
delete [] a[i];
delete [] b[i];
}
}
template<class type>
void add(type *array[], const int nRow, const int nCol)
{
for(unsigned i = 0; i < nRow; i++)
array[i] = new type[nCol];
for(unsigned i = 0; i < nRow; i++)
{
for(unsigned j = 0; j < nCol; j++)
cin >> array[i][j];
cout << endl;
}
}
template<class type>
void print(type *array[], const int nRow, const int nCol)
{
for(unsigned i = 0; i < nRow; i++)
{
for(unsigned j = 0; j < nCol; j++)
cout << setw(4) << array[i][j];
cout << endl;
}
}
Нужно ортогоналезировать данную матрицу.
Для этого нужно воспользоватся формулой(см. скрин).
Помогите реализовать данную формулу (т.н нужна функция аргументы которой будут: начальная матрица и матрица которая должна получится).
Заранее благодарен
#include <iostream>
#include <iomanip>
using namespace std;
template<class type>
void add(type *array[], int nRow, int nCol);
template<class type>
void print(type *array[], const int nRow, const int nCol);
int main()
{
int nRow, nCol;
cout << "Input nRow: ";
cin >> nRow;
cout << "Input nCol: ";
cin >> nCol;
int *a[nCol], *b[nCol];
add(a, nRow, nCol);
add(b, nRow, nCol);
print(a, nRow, nCol);
for(unsigned i = 0; i < nRow; i++)
b[i][0] = a[i][0]; //Первый столбец новой матрицы идентичен первому
//столбцу исходной
for(unsigned i = 0; i < nRow; i++)
{
delete [] a[i];
delete [] b[i];
}
}
template<class type>
void add(type *array[], const int nRow, const int nCol)
{
for(unsigned i = 0; i < nRow; i++)
array[i] = new type[nCol];
for(unsigned i = 0; i < nRow; i++)
{
for(unsigned j = 0; j < nCol; j++)
cin >> array[i][j];
cout << endl;
}
}
template<class type>
void print(type *array[], const int nRow, const int nCol)
{
for(unsigned i = 0; i < nRow; i++)
{
for(unsigned j = 0; j < nCol; j++)
cout << setw(4) << array[i][j];
cout << endl;
}
}
Нужно ортогоналезировать данную матрицу.
Для этого нужно воспользоватся формулой(см. скрин).
Помогите реализовать данную формулу (т.н нужна функция аргументы которой будут: начальная матрица и матрица которая должна получится).
Заранее благодарен