资源简介
C++ 矩阵类 实现常用的矩阵操作。例如,矩阵加法,数乘,矩阵乘法,获取子式等操作
代码片段和文件信息
// Matrix.cpp: implementation of the CMatrix class.
//
//////////////////////////////////////////////////////////////////////
#include “stdafx.h“
#include “Matrix.h“
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction CMatrix
//////////////////////////////////////////////////////////////////////
IMPLEMENT_SERIAL(CMatrix Cobject 1) ;
#ifdef _DEBUG
int CMatrix::m_NextobjectNumber = 1 ;
#endif
CMatrix::CMatrix()
{
#ifdef _DEBUG
// so we can regonise each individual object
m_objectNumber = m_NextobjectNumber++ ;
TRACE(“Creating CMatrix object %1d - default constructor\n“ m_objectNumber) ;
#endif
// default constructor create a 1 * 1 array
m_NumColumns = 1 ;
m_NumRows = 1 ;
m_pData = NULL ;
m_pData = AllocateMemory(m_NumColumns m_NumRows) ;
IncrementReferenceCount() ; // count the reference to this memory
}
CMatrix::CMatrix(const CMatrix &other)
{
#ifdef _DEBUG
// so we can regonise each individual object
m_objectNumber = m_NextobjectNumber++ ;
TRACE(“Creating CMatrix object %1d - copy constructor other = %1d\n“ m_objectNumber other.m_objectNumber) ;
#endif
// copy constructor
m_pData = NULL ;
// use the other objects data pointer
m_NumColumns = other.m_NumColumns ;
m_NumRows = other.m_NumRows ;
m_pData = other.m_pData ; // copy the pointer
IncrementReferenceCount() ; // this thread can get the mutex multiple times without blocking
}
CMatrix::CMatrix(int nCols int nRows)
{
#ifdef _DEBUG
// so we can regonise each individual object
m_objectNumber = m_NextobjectNumber++ ;
TRACE(“Creating CMatrix object %1d - size constructor\n“ m_objectNumber) ;
#endif
// size constructor
ASSERT(nCols > 0) ; // matrix size error
ASSERT(nRows > 0) ; // matrix size error
m_pData = NULL ;
m_NumColumns = nCols ;
m_NumRows = nRows ;
m_pData = AllocateMemory(m_NumColumns m_NumRows) ;
IncrementReferenceCount() ; // count the reference to this memory
}
CMatrix::CMatrix(int size bool set_diagonal)
{
// construct a square matrix with 1.0‘s on the diagonal if required
#ifdef _DEBUG
// so we can regonise each individual object
m_objectNumber = m_NextobjectNumber++ ;
TRACE(“Creating CMatrix object %1d - square size constructor\n“ m_objectNumber) ;
#endif
// size constructor
ASSERT(size > 0) ; // matrix size error
m_pData = NULL ;
m_NumColumns = size ;
m_NumRows = size ;
m_pData = AllocateMemory(m_NumColumns m_NumRows) ;
IncrementReferenceCount() ; // count the reference to this memory
// set the dialognal if required
if (set_diagonal)
{
for (int i = 0 ; i < size ; ++i)
SetElement(i i 1.0) ;
}
}
// creates a CMatrix object from a SafeArray that contains a 2D matrix
// Note that you will probably have to call “VariantClear“ to correctly de-allocate
//
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 35902 2011-10-21 11:45 MyMatrix.cpp
文件 8674 2011-10-19 14:20 MyMatrix.h
相关资源
- 计算机图形学直线段的扫描转换C++实
- 50道习题源程序.zip
- RTCM 3.0解码C++代码
- 矩阵相乘c语言编程
- 批量16位图像转8位
- C++数值排序
- C++大作业———医院病人看病情景代
- OpenKE在windows环境下运行的C++动态链接
- 基于Qt5.9Creator的一个简单socket通信C
- 求两点之间所有路径的C++代码
- C++ 跨平台 异步消息队列
- 矩阵的qr分解,特征值计算,谱分解
- VC++对话框CDialog的全屏显示及控件居中
- VC++中对Access数据库操作
- VC++ OpenGL三维物体建模--雨伞的绘制(
- 马尔科夫链的C++代码实现
- 基于PCL、VTK的切片法计算三维模型的
- C++课程设计 电煤气管理系统
- 超级效率的FFT的代码(C语言)
- 灰度预测模型C语言源代码
- 仿QQ MFC 程序
- DTW算法 C++实现
- 最简单的C++静态调用DLL
- 用C++设计一个立方体类Box,它能计算
- 林锐 《高质量C/C++编程》
- c语言实现矩阵求逆程序
- C++ 实现的HTTP协议打包解析器
- C++ Primer Plus第6版_中英文版两个_带书
- C++实现的FTP服务器
- C++家庭财务管理系统
评论
共有 条评论