前言

这是前几个学期面向对象程序设计课程的大作业,这两天完完整整的重写了一遍,这份作业能够很好的涵盖C++的基础部分,以此来复习C++的基础语法部分,忘记有关功能的实现时可以查看源码

实现的涉及核心内容包括但不限于:

动态内存,类与对象的基本使用,深拷贝,运算符的重载(全局函数和成员函数),泛型(模板), 文件和流…

参考:

《C++ Primer》中文第五版

W3Cchool C++教程

模板约束

https://blog.csdn.net/guxch/article/details/110795047

https://www.zhihu.com/question/403570202/answer/1351024448

逆矩阵求解算法参考

https://blog.csdn.net/qithon/article/details/80100029?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165873888016781667819434%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=165873888016781667819434&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduend~default-1-80100029-null-null.142

https://blog.csdn.net/m0_46201544/article/details/125012646?ops_request_misc=&request_id=&biz_id=102&utm_term=%20C++%20

矩阵幂运算,快速幂算法参考

https://blog.csdn.net/qq_34401994/article/details/104646211

高斯滤波算法参考

https://blog.csdn.net/dcrmg/article/details/52304446?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522162400765316780366538782%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=162400765316780366538782&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allbaidu_landing_v2~default-1-52304446.pc_search_result_before_js&utm_term=c%2B%2B

完整代码

//
// Created by Xmx on 2022/7/26.
//#include <iostream>
#include <cmath>
#include <fstream>
#include <initializer_list>using namespace std;template <class T>
class Matrix
{
public:// 无参构造函数Matrix() {}// 有参构造函数Matrix(int rows, int cols, T init_value){set_rows(rows);set_cols(cols);new_mat();for (int i = 0; i < get_rows(); ++i)for (int j = 0; j < get_cols(); ++j)mat_[i][j] = init_value;}// 析构函数~Matrix(){cout << "~Matrix" << endl;delete_mat();}// done:// 有参构造函数, 使用初始化列表Matrix(initializer_list<initializer_list<T>> listList){rows_ = (listList.begin())->size();cols_ = listList.size();new_mat(); // 分配内存auto pr = listList.begin();auto pc = pr->begin();for (int i = 0; i < get_rows(); i++, pr++){pc = pr->begin();for (int j = 0; j < get_cols(); j++, pc++)mat_[i][j] = *pc;}}// 重载拷贝构造函数, 实现深拷贝Matrix<T>(const Matrix<T> &matrix){this->rows_ = matrix.get_rows();this->cols_ = matrix.get_cols();new_mat(); // 为拷贝接受对象开辟内存//拷贝数值for (int i = 0; i < matrix.get_rows(); ++i)for (int j = 0; j < matrix.get_cols(); ++j)mat_[i][j] = matrix.mat_[i][j];}//! 重载= 必须通过成员函数实现Matrix<T> &operator=(const Matrix<T> &matrix){// 若其在堆区, 先释放mat_指针,再深拷贝即可if (mat_ != NULL){delete mat_;mat_ = NULL;}// 深拷贝this->rows_ = matrix.get_rows();this->cols_ = matrix.get_cols();new_mat();for (int i = 0; i < matrix.get_rows(); ++i)for (int j = 0; j < matrix.get_cols(); ++j)mat_[i][j] = matrix.mat_[i][j];return *this;}bool operator==(const Matrix<T> &other){if (this->rows_ == other.rows_ && this->cols_ == other.cols_){if (this->mat_ != NULL && other.mat_ != NULL){for (int i = 0; i < this->rows_; i++)for (int j = 0; j < this->cols_; j++)if (this->mat_[i][j] != other.mat_[i][j])return false;return true;}elsereturn false;}elsereturn false;}bool operator!=(const Matrix<T> &other){if (this->rows_ == other.rows_ && this->cols_ == other.cols_){if (this->mat_ != NULL && other.mat_ != NULL){for (int i = 0; i < this->rows_; i++)for (int j = 0; j < this->cols_; j++)if (mat_[i][j] != other.mat_[i][j])return true;return true;}elsereturn true;}elsereturn true;}// 申请矩阵空间void new_mat(){this->mat_ = new T *[get_rows()];for (int i = 0; i < get_rows(); i++){this->mat_[i] = new T[get_cols()];}}// 释放矩阵空间void delete_mat(){if (mat_ != NULL){for (int i = 0; i < get_rows(); i++)delete[] this->mat_[i];delete[] mat_;mat_ = NULL;}}// *  ------------------------- 访问器与修改器 ---------------------------- *void set_rows(int rows){this->rows_ = rows;}void set_cols(int cols){this->cols_ = cols;}int get_rows() const{return this->rows_;}int get_cols() const{return this->cols_;}//* --------------------------- 文件和流 -------------------------------- *void load_matrix(string filename){ifstream input;// input>>noskipws; //! 不忽略空格, 为了方便写入矩阵,不跳过空格input.open(filename);string read_contents = "";string temp;//! 读写模板// while (input>>temp)// {//     /* code *///     read_contents += temp;// }// cout << read_contents << endl;if (input.is_open()){int rows, cols;input >> rows >> cols;set_rows(rows);set_cols(cols);new_mat();for (int i = 0; i < get_rows(); i++)for (int j = 0; j < get_cols(); j++)input >> mat_[i][j];cout << "read the txt successfully" << endl;cout << "rows: " << rows << " cols: " << cols << endl;input.close();cout << "The Matrix has been read successfully: " << endl;cout << *this << endl;}elsecout << "File Opening Failed" << endl;}void write_matrix(string filename){ofstream output(filename);if (output.is_open()){output << *this << endl;output.close();cout << "Matrix has been written" << endl;}elsecout << "File Opening Failed" << endl;}// void show_mat()// {//     cout << endl;//     for (int i = 0; i < get_rows(); i++)//     {//         for (int j = 0; j < get_cols(); j++)//         {//             cout << this->mat_[i][j] << " ";//         }//         cout << endl;//     }//     cout << endl;// }// * ------------------------ 矩阵的基本运算函数 -------------------------- *void swap_element(T &element1, T &element2){T temp = element1;element1 = element2;element2 = temp;}// 交换两行void swap_rows(int row1, int row2){for (int i = 0; i < get_cols(); i++)swap_element(mat_[row1][i], mat_[row2][i]);}// 交换两列void swap_cols(int col1, int col2){for (int i = 0; i < get_rows(); i++)swap_element(mat_[i][col1], mat_[i][col2]);}// *  ------------------------- 运算符重载的友元声明 ------------------------ *template <class U>friend istream &operator>>(istream &in, Matrix<U> &A); //! >>template <class U>friend ostream &operator<<(ostream &out, Matrix<U> &A); //! <<template <class U>friend Matrix<U> operator+(const Matrix<U> &A, const U &k); //! A + ktemplate <class U>friend Matrix<U> operator+(const U &k, const Matrix<U> &A); //! k + Atemplate <class U>friend Matrix<U> operator-(const Matrix<U> &A, const U &k); //! A - ktemplate <class U>friend Matrix<U> operator-(const U &k, const Matrix<U> &A); //! k - Atemplate <class U>friend Matrix<U> operator*(const U &k, const Matrix<U> &A); //! k * Atemplate <class U>friend Matrix<U> operator*(const Matrix<U> &A, const U &k); //! A * ktemplate <class U>friend Matrix<U> operator/(const U &k, const Matrix<U> &A); //! k / Atemplate <class U>friend Matrix<U> operator/(const Matrix<U> &A, const U &k); //! A / ktemplate <class U>friend Matrix<U> operator+(const Matrix<U> &A, const Matrix<U> &B); //! A + Btemplate <class U>friend Matrix<U> operator-(const Matrix<U> &A, const Matrix<U> &B); //! A - Btemplate <class U>friend Matrix<U> operator*(const Matrix<U> &A, const Matrix<U> &B); //! A * Btemplate <class U>friend Matrix<U> operator/(const Matrix<U> &A, const Matrix<U> &B); //! A / Btemplate <class U>friend Matrix<U> operator^(const Matrix<U> &A, const U &B); //! A^k//* ------------------------- 静态成员函数生成基本矩阵 --------------------------- */// 零矩阵static Matrix<T> zeros(int rows, int cols){return Matrix<T>(rows, cols, 0);}// 单位矩阵static Matrix<T> units(int size){Matrix<T> result = Matrix<T>::zeros(size, size); // 先生成一个size大小的 "方零矩阵"for (int i = 0; i < result.get_cols(); i++)      // 修改对角线元素result.mat_[i][i] = 1;return result;}//! done: 求逆矩阵(高斯消元实现)template <class U>static Matrix<U> inverse(const Matrix<U> &A){double eps = 1e-6;// 返回double类型,防止精度丢失Matrix<double> temp = Matrix<double>::augmented_E(A);for (int i = 0; i < temp.get_rows(); i++){if (fabs(temp.mat_[i][i]) < eps){int j;for (j = i + 1; j < temp.get_rows(); j++)if (fabs(temp.mat_[i][j]) > eps)break;}// 初等变换实现消元for (int i = 0; i < temp.get_rows(); i++){double t = temp.mat_[i][i];// 将temp.mat_[i][i] = 1;for (int j = i; j < temp.get_cols(); j++)temp.mat_[i][j] /= t;for (int j = i + 1; j < temp.get_rows(); j++){double tt = -1 * (temp.mat_[j][i] / temp.mat_[i][i]);for (int k = i; k < temp.get_cols(); k++)temp.mat_[j][k] += tt * temp.mat_[i][k];}}}for (int i = temp.get_rows() - 1; i >= 0; i--){for (int j = i - 1; j >= 0; j--){double tt = -1 * (temp.mat_[j][i] / temp.mat_[i][i]);for (int k = i; k < temp.get_cols(); k++)temp.mat_[j][k] += tt * temp.mat_[i][k];}}// 将temp左半部分传给resultMatrix<double> result(A.get_rows(), A.get_cols(), 0);for (int i = 0; i < result.get_rows(); i++)for (int j = result.get_rows(); j < 2 * result.get_rows(); j++)result.mat_[i][j - result.get_rows()] = temp.mat_[i][j];// cout<<temp;return result;}//! done: 返回A的增广矩阵A|Estatic Matrix<T> augmented_E(const Matrix<T> &A){int rows = A.get_rows();int cols = A.get_rows() + A.get_cols();Matrix<T> result = Matrix<T>(rows, cols, 0);for (int i = 0; i < result.get_rows(); i++){for (int j = 0; j < result.get_cols(); j++){if (j < A.get_cols()){result.mat_[i][j] = A.mat_[i][j];}else{if (j == A.get_cols() + i)result.mat_[i][j] = 1;elseresult.mat_[i][j] = 0;}}}return result;}//! done: 增广矩阵A' , 返回A的增广矩阵static Matrix<T> augmented(const Matrix<T> &A, const T *input, int len){int rows = A.get_rows();int cols = A.get_rows() + 1;for (int i = 0; i < len; i++)cout << input[i] << " ";// input数组长度为A的行数满足条件,可以生成增广矩阵if (len == rows){Matrix<T> result = Matrix<T>(rows, cols, 0);for (int i = 0; i < result.get_rows(); i++){for (int j = 0; j < result.get_cols(); j++){if (j < A.get_cols())result.mat_[i][j] = A.mat_[i][j];elseresult.mat_[i][j] = input[i];}}return result;}elsereturn Matrix<T>::zeros(1, 1);}//! done: 高斯消元(初等变换法)求解线性方程static string Gauss_eliminate(const Matrix<T> &A){Matrix<T> temp = A;           // 用于计算的矩阵double ratio = 0, eps = 1e-6; // 默认最小主元素int n = temp.get_rows();      // 方程个数double result[n];             // 存储结果的数组string result_string = "";// 消元for (int k = 0; k < (n); k++){for (int i = (k + 1); i < n; i++){if (abs(temp.mat_[k][k]) < eps)return "No solution!";double ratio = temp.mat_[i][k] / temp.mat_[k][k];for (int j = (k + 1); j < (n + 1); j++)temp.mat_[i][j] -= ratio * temp.mat_[k][j];temp.mat_[i][k] = 0;}}result[n - 1] = temp.mat_[n - 1][n] / temp.mat_[n - 1][n - 1]; // 回代for (int i = (n - 2); i >= 0; i--){double sum = 0;for (int j = (i + 1); j < n; j++){sum += temp.mat_[i][j] * result[j];result[i] = (temp.mat_[i][n] - sum) / temp.mat_[i][i];}}// 生成结果字符串for (int i = 0; i < n; i++)result_string += "\nresult[" + to_string(i) + "]=" + to_string(result[i]) + "\n";return result_string;}//! done: 高斯核矩阵static Matrix<double> Gauss_kernel(int size, double sigma){Matrix<double> result = Matrix<double>::zeros(size, size);const double PI = 4.0 * atan(1.0); // 圆周率赋值int center = size / 2;double sum = 0;for (int i = 0; i < size; i++){for (int j = 0; j < size; j++){result.mat_[i][j] = (1 / (2 * PI * sigma * sigma)) *exp(-((i - center) * (i - center) + (j - center) * (j - center)) /(2 * sigma * sigma));sum += result.mat_[i][j];}}return result;}//! done: H 为高斯滤波核矩阵, A 需要高斯滤波的矩阵, 返回滤波后的矩阵static Matrix<double> Gauss_filter(const Matrix<T> &A, const Matrix<double> &H){Matrix<double> result = Matrix::zeros(A.get_rows(), A.get_cols());for (int i = 0; i < result.get_rows(); i++)for (int j = 0; j < result.get_cols(); j++)result.mat_[i][j] = A.mat_[i][j] * H.mat_[i][j];return result;}private:int rows_;int cols_;T **mat_;
};//*  --------------------------- 运算符重载 ------------------------------------- *///! done: 重载>>
template <class U>
istream &operator>>(istream &in, Matrix<U> &A)
{cout << "Input the rows and columns for the matrix" << endl;in >> A.rows_ >> A.cols_;A.new_mat();for (int i = 0; i < A.get_rows(); i++)for (int j = 0; j < A.get_cols(); j++)in >> A.mat_[i][j];return in;
}//! done: 重载<<
template <class U>
ostream &operator<<(ostream &out, Matrix<U> &A)
{for (int i = 0; i < A.get_rows(); i++){out << " [";for (int j = 0; j < A.get_cols(); j++)out << " " << A.mat_[i][j];out << " ]" << endl;}out << endl;return out;
}//! done A + k
template <class U>
Matrix<U> operator+(const Matrix<U> &A, const U &k)
{if (A.get_cols() == A.get_rows()) // A 为方针,可以运算{Matrix<U> result = Matrix<U>(A);for (int i = 0; i < result.get_cols(); i++) // A + kEresult.mat_[i][i] += k;return result;}else // 无法运算,返回1×1单位矩阵return Matrix<U>::zeros(1, 1);
}//! done k + A
template <class U>
Matrix<U> operator+(const U &k, const Matrix<U> &A)
{if (A.get_cols() == A.get_rows()) // A 为方针,可以运算{Matrix<U> result = Matrix<U>(A);for (int i = 0; i < result.get_cols(); i++) // kE + Aresult.mat_[i][i] += k;return result;}else // 无法运算,返回1×1单位矩阵return Matrix<U>::zeros(1);
}//! done: A - k
template <class U>
Matrix<U> operator-(const Matrix<U> &A, const U &k)
{if (A.get_cols() == A.get_rows()) // A 为方针,可以运算{Matrix<U> result = Matrix<U>(A);for (int i = 0; i < result.get_cols(); i++) // A - kEresult.mat_[i][i] -= k;return result;}else // 无法运算,返回1×1单位矩阵return Matrix<U>::zeros(1);
}//! done k - A
template <class U>
Matrix<U> operator-(const U &k, const Matrix<U> &A)
{if (A.get_cols() == A.get_rows()) // A 为方针,可以运算{Matrix<U> result = Matrix<U>(A);for (int i = 0; i < result.get_cols(); i++) // kE - Afor (int j = 0; j < result.get_cols(); j++){if (i == j)result.mat_[i][j] = k - result.mat_[i][j];elseresult.mat_[i][j] = -result.mat_[i][j];}return result;}else // 无法运算,返回1×1单位矩阵return Matrix<U>::zeros(1);
}//! done: k * A
template <class U>
Matrix<U> operator*(const U &k, const Matrix<U> &A)
{Matrix<U> result = Matrix<U>(A);for (int i = 0; i < result.get_rows(); i++)for (int j = 0; j < result.get_cols(); j++)result.mat_[i][j] = result.mat_[i][j] * k;return result;
}//! done: A * k
template <class U>
Matrix<U> operator*(const Matrix<U> &A, const U &k)
{Matrix<U> result = Matrix<U>(A);for (int i = 0; i < result.get_rows(); i++)for (int j = 0; j < result.get_cols(); j++)result.mat_[i][j] = result.mat_[i][j] * k;return result;
}//! done: k / A
template <class U>
Matrix<U> operator/(const U &k, const Matrix<U> &A)
{// k / A = kE * A^-1// A 为方针,可以运算if (A.get_rows() == A.get_cols()){Matrix<U> result = Matrix<U>(A);Matrix<U> kE = Matrix<U>::units(A.get_rows());kE = kE * k; // 生成kEreturn kE * Matrix<U>::inverse(A);}else // 无法运算,返回零矩阵return Matrix<U>::zeros(1, 1);
}//! done: A / k
template <class U>
Matrix<U> operator/(const Matrix<U> &A, const U &k)
{Matrix<U> result = Matrix<U>(A);for (int i = 0; i < result.get_rows(); i++)for (int j = 0; j < result.get_cols(); j++)result.mat_[i][j] = result.mat_[i][j] / k;return result;
}//! done: A + B
template <class U>
Matrix<U> operator+(const Matrix<U> &A, const Matrix<U> &B)
{// A 与 B 维度相同if ((A.get_cols() == B.get_cols()) && (A.get_rows() == B.get_rows())){Matrix<U> result = Matrix<U>(A);for (int i = 0; i < result.get_rows(); i++)for (int j = 0; j < B.get_cols(); j++)result.mat_[i][j] += B.mat_[i][j];return result;}else // 无法运算,返回零矩阵return Matrix<U>::zeros(1, 1);
}//! done: A - B
template <class U>
Matrix<U> operator-(const Matrix<U> &A, const Matrix<U> &B)
{// A 与 B 维度相同if ((A.get_cols() == B.get_cols()) && (A.get_rows() == B.get_rows())){Matrix<U> result = Matrix<U>(A);for (int i = 0; i < result.get_rows(); i++)for (int j = 0; j < B.get_cols(); j++)result.mat_[i][j] -= B.mat_[i][j];return result;}else // 无法运算,返回零矩阵return Matrix<U>::zeros(1, 1);
}//! done: A * B
template <class U>
Matrix<U> operator*(const Matrix<U> &A, const Matrix<U> &B)
{// 先判断能否运算if (A.get_cols() == B.get_rows()){Matrix<U> result = Matrix<U>(A.get_rows(), B.get_cols(), 0);for (int i = 0; i < result.get_rows(); i++)for (int j = 0; j < result.get_cols(); j++)for (int k = 0; k < result.get_cols(); k++) // 所在行所在列元素相乘result.mat_[i][j] += A.mat_[i][k] * B.mat_[k][j];return result;}else // 无法运算,返回零矩阵return Matrix<U>::zeros(1, 1);
}//! done: A / B
template <class U>
Matrix<U> operator/(const Matrix<U> &A, const Matrix<U> &B)
{// A / B == A * B^-1// 先判断能否运算if (A.get_cols() == B.get_rows())return A * (Matrix<U>::inverse(B));elsereturn Matrix<U>::zeros(1, 1);
}//! done: A^k
template <class U>
Matrix<U> operator^(const Matrix<U> &A, int k)
{Matrix<U> result = Matrix<U>::units(A.get_cols());Matrix<U> temp = A;// 快速幂进行运算while (k){if (k % 2)result = result * temp;k /= 2;temp = temp * temp;}return result;
}int main()
{// Matrix<int> matrix1(3, 3, 3);// Matrix<double> matrix1_4(3, 4, 4);// Matrix<int> matrix2(4, 4, 4);// // Matrix<double> matrix3 = { {5,5,-1,7,54},{4,-9,20,12,-6},{9,-18,-3,1,21},{ 61,-8,-10,3,13 },{ 29,-28,-1,4,14 } };// // Matrix<int> matrix4 = Matrix<int>(matrix1);// Matrix<double> matrix5 = matrix1_4 * (0.3);// Matrix<int> matrix6 = Matrix<int>::units(3);// matrix1.show_mat();// matrix2.show_mat();// // matrix3.show_mat();// // matrix4.show_mat();// matrix5.show_mat();// matrix6.show_mat();// cout<<matrix6;// Matrix<double> matrix = Matrix<double>::augmented_E(matrix1_4);// matrix.swap_rows(0,1);// cout << matrix;// Matrix<double> matrix10;// cin >> matrix10;// Matrix<double> temp = Matrix<double>::inverse(matrix10);// Matrix<double> temp1 = Matrix<double>::inverse(matrix10);// cout << temp;// temp = temp ^ 2;// cout<<temp;// temp1 = temp1 * temp1;// cout<<temp1;// cout <<( matrix != matrix);//! 测试=, ==, != 重载Matrix<int> m1(3, 3, 3);Matrix<int> m2(3, 3, 4);cout << m1 << m2 << endl;cout << (m1 == m2);//     double input[] = {6,18,7};//     cout<<"len = "<< sizeof(input)/sizeof(input[0])<<endl;//      Matrix<double> Equations;//      cin >> Equations;//      Equations = Matrix<double>::augmented(Equations,input,sizeof(input)/sizeof(input[0]));//      cout<< Equations;//      cout<< Matrix<double>::Gauss_eliminate(Equations);//! 测试高斯滤波Matrix<double> temp(5, 5, 100);cout << temp << endl;temp = Matrix<double>::Gauss_filter(temp, Matrix<double>::Gauss_kernel(5, 5));cout << temp;//! 测试文件和流// Matrix<double> matrix_IO;// matrix_IO.load_matrix("input.txt");// matrix_IO.write_matrix("output.txt");// 测试初始化列表initializer_list<initializer_list<int>> initializerL_mat = {{1, 2, 3}, {2, 2, 2}, {3, 3, 3}};Matrix<int> matrix_initializer(initializerL_mat);cout << matrix_initializer;
}

作业要求:

  1. 实现一个矩阵类,包含以下功能:

​ 基本成员

​ a) rows_行,cols_列,double** mat,矩阵元素

​ b) get_rows()返回行数;get_cols()返回列数

  1. 矩阵类的构造函数

​ a) 默认构造函数,生成一个1,1列的矩阵

​ Matrix mat;

​ b) 生成行列分别为rows, cols的矩阵

​ Matrix mat(rows, cols);

​ c) 生成行列分别为rows, cols,初始值为init_value的矩阵

​ Matrix mat(rows, cols, init_value);

​ d) 利用初始化列表生成矩阵

​ Matrix mat = {{1,2,3,4}, {5,6,7,8}};

  1. 析构函数

  2. 拷贝构造函数与赋值运算符函数(实现深拷贝)

  3. 实现基本运算符重载函数,其中 A 表示矩阵,k表示标量(一个实数)。如表1所示。

  4. 静态函数生成基本矩阵

​ a) 零矩阵 Matrix::zeros(rows, cols);

​ b) 单位矩阵 Matrix::eye(size);

​ c) 均匀分布随机矩阵[1] Matrix::randu(rows, cols);

​ d) 高斯分布随机矩阵[2] Matrix::randn(rows, cols);

矩阵类基本运算符

操作符 说明
A + k 矩阵对应元素加上标量
k + A 标量加上矩阵对应元素
A - k 矩阵对应元素减去标量
A ∗ k 矩阵对应元素乘以标量
k ∗ A 标量乘以矩阵对应元素
A + B 矩阵对应元素加法
A - B 矩阵对应元素减法
A * B 矩阵乘法
A % B 矩阵对应元素乘法
A / B 矩阵对应元素乘法
A ^ k 矩阵 A 的 k 次幂 (可以采用矩阵快速幂实现)
  1. 应用于方程组的矩阵函数

​ a) 增广矩阵 Matrix Ab = AugmentMatrix(A, B);

​ 对于矩阵A,B的构成的增广矩阵Ab为

​ 其中AB矩阵的行数数应保证相同。

​ b) 逆矩阵 Matrix IA = Inverse(A);

​ 逆矩阵可以通过对增广矩阵IA做高斯消元法实现,其中,I 是矩阵A的同型单位矩阵。

​ c) 实现高斯消元法求解线性方程组 Matrix x = GaussianElimination(A, b);

  1. 高斯滤波

​ a) 生成高斯核 Matrix H = GaussianKernel(k, sigma); 其中k表示高斯核尺寸, sigma表示方差。

​ b) 实现高斯滤波 Matrix B = GaussianFilter(A, H)

  1. 实现成员函数实现将矩阵读写函数。比如

​ Matrix mat;

​ mat.Load(filename);

​ mat.Write(filename);

C++ 实现 Matrix (矩阵)类相关推荐

  1. JavaScript实现完整的matrix矩阵类(附完整源码)

    JavaScript实现完整的matrix矩阵类(附完整源码) matrix.js完整源代码 matrix.js完整源代码 export const shape = (m) => {const ...

  2. [Android] 使用Matrix矩阵类对图像进行缩放、旋转、对比度、亮度处理

        前一篇文章讲述了Android拍照.截图.保存并显示在ImageView控件中,该篇文章继续讲述Android图像处理技术,主要操作包括:通过打开相册里的图片,使用Matrix对图像进行缩放. ...

  3. 7-67 使用二维数组实现Matrix(矩阵)。 (60 分)

    使用二维数组实现Matrix(矩阵). 定义Matrix(矩阵)类,要求如下: a) 变量:matrix(int型二维数组),row(行数),column(列数): b) 方法:实现两个矩阵的乘法,所 ...

  4. python定义一个1xn矩阵_Python实现的矩阵类实例

    本文实例讲述了Python实现的矩阵类.分享给大家供大家参考,具体如下: 科学计算离不开矩阵的运算.当然,python已经有非常好的现成的库: 我写这个矩阵类,并不是打算重新造一个轮子,只是作为一个练 ...

  5. 利用二维数组实现一个矩阵类:Matrix

    利用二维数组实现一个矩阵类:Matrix.要求提供以下操作: (1)set(int row, int col, double value):将第row行第col列的元素赋值为value: (2)get ...

  6. 利用二维数组(double[])实现一个矩阵类:Matrix。要求提供以下方法:(1)set(int row, int col, double value):将第row行第col列的元素赋值为valu

    利用二维数组(double[])实现一个矩阵类:Matrix.要求提供以下方法:(1)set(int row, int col, double value):将第row行第col列的元素赋值为valu ...

  7. 实现一个矩阵类 Matrix

    @矩阵类,MatrixTOC 欢迎使用Markdown编辑器 import java.util.Scanner; import java.util.HashMap; import java.util. ...

  8. Android 自定义View ——Matrix (矩阵)

    Matrix的作用: Matrix类包含一个3x3矩阵,用于转换坐标 Matrix (矩阵) 的原理很遗憾自己目前也是含糊的很,这里就不说了,记录自己在项目使用的方法, 这里就简单的记录下Matrix ...

  9. Eigen(1):Matrix模板类

    Matrix是一个模板类,利用模板类可以定义矩阵类. 矩阵类模板: 1Matrix类有6个模板参数,只需要了解前3个就好了. Matrix<typename Scalar, int RowsAt ...

  10. 理解CSS3 transform中的Matrix(矩阵)

    一.哥,我被你吓住了 打架的时候会被块头大的吓住,学习的时候会被奇怪名字吓住(如"拉普拉斯不等式").这与情感化设计本质一致:界面设计好会让人觉得这个软件好用! 所以,当看到上面& ...

最新文章

  1. 原创 | IJCAI 2020灭霸式拒稿,AI审稿是否更公平?
  2. 考驾照选择 AI 教练,心态稳定不骂人
  3. Web 性能测试-内存泄漏测试方法之chrome内存快照
  4. 人工智能的策略,如果国家优先发展”梦想成真”?
  5. 信道检测手机软件 ios_【手机软件】云听:稀有神器,移动音频的国家队,某拉雅资源它都有!...
  6. Java环境配置(linux安装jdk8)
  7. python 读取csv带表头_python读csv文件时指定行为表头或无表头的方法
  8. github怎么自动更新被人更新过的项目_win10老是自动更新怎么办?如何完全禁止win10自动更新?...
  9. Fastboot驱动及安装
  10. Subclipse使用说明
  11. python外包凹多边形生成_用Opencv python裁剪图像中的凹多边形
  12. 苹果电脑如何改id?这篇文章帮你搞定
  13. 青果教务管理系统存储型XSS 一枚
  14. Length和lengthb的区别
  15. 使用PHP获取图像文件的EXIF信息
  16. 【千纸诗书】—— PHP/MySQL二手书网站后台开发之项目设计
  17. win10连接dns服务器未响应,win10提示dns服务器未响应怎么解决_win10网络诊断为dns未响应修复方法...
  18. 社群是什么?真正的社群是怎么样的?
  19. 新浪微博API[赞]接口和[取消赞]接口
  20. 如何起Linux服务器的21端口,linux下开启ftp的21号端口

热门文章

  1. 物联网发展的基石——传感器
  2. JavaScript正则表达式的学习
  3. SQL语句查询电影评分案例分析
  4. flowable 监听器
  5. Spark Standalone -- 独立集群模式、Spark 提交任务的两种模式、spark在yarn上运行的环境搭建、自己写的spark代码如何提交到yarn上并运行...
  6. 美服无限火力是哪个服务器,为啥无限火力不能永久开放?其实美服曾经开放过,但结果太残酷...
  7. pyaudio安装失败的解决方法
  8. 2022届浙江工业大学计算机专硕考研上岸经验贴
  9. 2014年24段魔尺如何变球的视频教程
  10. 24段魔尺,骆驼,小狗,金鱼,蝴蝶结