资源简介
这个一个老外写的矩阵类,用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 Matrix.cpp
文件 8674 2011-10-19 14:20 Matrix.h
相关资源
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
- FTP客户端源码(c++)
- c++ 画图(14Qt-XPS)
- c++多边形交并差运算
- VC++基于OpenGL模拟的一个3维空间模型
评论
共有 条评论