误差理论与测量平差课程设计实验报告讲解Word文档格式.docx
- 文档编号:4788738
- 上传时间:2023-05-04
- 格式:DOCX
- 页数:46
- 大小:1.12MB
误差理论与测量平差课程设计实验报告讲解Word文档格式.docx
《误差理论与测量平差课程设计实验报告讲解Word文档格式.docx》由会员分享,可在线阅读,更多相关《误差理论与测量平差课程设计实验报告讲解Word文档格式.docx(46页珍藏版)》请在冰点文库上搜索。
现将该程序的Matrix.cpp文件附录如下:
//Matrix.cpp
#include"
StdAfx.h"
Matrix.h"
#ifdef_DEBUG
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#definenewDEBUG_NEW
#endif
//Construction/Destruction
//基本构造函数
CMatrix:
:
CMatrix()
{
m_nNumColumns=1;
m_nNumRows=1;
m_pData=NULL;
BOOLbSuccess=Init(m_nNumRows,m_nNumColumns);
ASSERT(bSuccess);
}
//指定行列构造函数
//参数:
//1.intnRows-指定的矩阵行数
//2.intnCols-指定的矩阵列数
CMatrix(intnRows,intnCols)
m_nNumRows=nRows;
m_nNumColumns=nCols;
//初始化函数
//
//返回值:
BOOL型,初始化是否成功
BOOLCMatrix:
Init(intnRows,intnCols)
if(m_pData)
{
delete[]m_pData;
m_pData=NULL;
}
intnSize=nCols*nRows;
if(nSize<
0)
returnFALSE;
//分配内存
m_pData=newdouble[nSize];
if(m_pData==NULL)
//内存分配失败
if(IsBadReadPtr(m_pData,sizeof(double)*nSize))
//将各元素值置0
memset(m_pData,0,sizeof(double)*nSize);
returnTRUE;
//指定值构造函数
//3.doublevalue[]-一维数组,长度为nRows*nCols,存储矩阵各元素的值
CMatrix(intnRows,intnCols,doublevalue[])
SetData(value);
//设置矩阵各元素的值
//1.doublevalue[]-一维数组,长度为m_nNumColumns*m_nNumRows,存储
//矩阵各元素的值
无
voidCMatrix:
SetData(doublevalue[])
//emptythememory
memset(m_pData,0,sizeof(double)*m_nNumColumns*m_nNumRows);
//copydata
memcpy(m_pData,value,sizeof(double)*m_nNumColumns*m_nNumRows);
//方阵构造函数
//1.intnSize-方阵行列数
CMatrix(intnSize)
m_nNumRows=nSize;
m_nNumColumns=nSize;
BOOLbSuccess=Init(nSize,nSize);
ASSERT(bSuccess);
//2.doublevalue[]-一维数组,长度为nRows*nRows,存储方阵各元素的值
CMatrix(intnSize,doublevalue[])
//拷贝构造函数
//1.constCMatrix&
other-源矩阵
CMatrix(constCMatrix&
other)
m_nNumColumns=other.GetNumColumns();
m_nNumRows=other.GetNumRows();
//copythepointer
memcpy(m_pData,other.m_pData,sizeof(double)*m_nNumColumns*m_nNumRows);
//析构函数
~CMatrix()
//将方阵初始化为单位矩阵
MakeUnitMatrix(intnSize)
if(!
Init(nSize,nSize))
for(inti=0;
i<
nSize;
++i)
for(intj=0;
j<
++j)
if(i==j)
SetElement(i,j,1);
//将字符串转化为矩阵的值
//1.CStrings-数字和分隔符构成的字符串
//2.constCString&
sDelim-数字之间的分隔符,默认为空格
//3.BOOLbLineBreak-行与行之间是否有回车换行符,默认为真(有换行符)
//当该参数为FALSE时,所有元素值都在一行中输入,字符串的第一个
//数值应为矩阵的行数,第二个数值应为矩阵的列数
BOOL型,转换是否成功
FromString(CStrings,constCString&
sDelim/*="
"
*/,BOOLbLineBreak/*=TRUE*/)
if(s.IsEmpty())
//分行处理
if(bLineBreak)
CTokenizertk(s,"
\r\n"
);
CStringListListRow;
CStringsRow;
while(tk.Next(sRow))
{
sRow.TrimLeft();
sRow.TrimRight();
if(sRow.IsEmpty())
break;
ListRow.AddTail(sRow);
}
//行数
m_nNumRows=ListRow.GetCount();
sRow=ListRow.GetHead();
CTokenizertkRow(sRow,sDelim);
CStringsElement;
//列数
m_nNumColumns=0;
while(tkRow.Next(sElement))
m_nNumColumns++;
//初始化矩阵
if(!
Init(m_nNumRows,m_nNumColumns))
returnFALSE;
//设置值
POSITIONpos=ListRow.GetHeadPosition();
for(inti=0;
m_nNumRows;
i++)
sRow=ListRow.GetNext(pos);
intj=0;
CTokenizertkRow(sRow,sDelim);
while(tkRow.Next(sElement))
{
sElement.TrimLeft();
sElement.TrimRight();
doublev=atof(sElement);
SetElement(i,j++,v);
}
returnTRUE;
//不分行(单行)处理
CTokenizertk(s,sDelim);
CStringsElement;
tk.Next(sElement);
sElement.TrimLeft();
sElement.TrimRight();
m_nNumRows=atoi(sElement);
//列数
m_nNumColumns=atoi(sElement);
//初始化矩阵
//设置值
inti=0,j=0;
while(tk.Next(sElement))
sElement.TrimLeft();
sElement.TrimRight();
doublev=atof(sElement);
SetElement(i,j++,v);
if(j==m_nNumColumns)
j=0;
i++;
if(i==m_nNumRows)
//将矩阵各元素的值转化为字符串
//1.constCString&
//2BOOLbLineBreak-行与行之间是否有回车换行符,默认为真(有换行符)
CString型,转换得到的字符串
CStringCMatrix:
ToString(constCString&
*/,BOOLbLineBreak/*=TRUE*/)const
CStrings="
"
;
m_nNumColumns;
CStringss;
ss.Format("
%f"
GetElement(i,j));
s+=ss;
if(bLineBreak)
if(j!
=m_nNumColumns-1)
s+=sDelim;
else
if(i!
=m_nNumRows-1||j!
if(bLineBreak)
if(i!
=m_nNumRows-1)
s+="
returns;
//将矩阵指定行中各元素的值转化为字符串
//1.intnRow-指定的矩阵行,nRow=0表示第一行
RowToString(intnRow,constCString&
*/)const
CStrings="
if(nRow>
=m_nNumRows)
returns;
for(intj=0;
CStringss;
ss.Format("
GetElement(nRow,j));
s+=ss;
if(j!
s+=sDelim;
//将矩阵指定列中各元素的值转化为字符串
//1.intnCol-指定的矩阵行,nCol=0表示第一列
ColToString(intnCol,constCString&
if(nCol>
=m_nNumColumns)
GetElement(i,nCol));
if(i!
//设置指定元素的值
//3.doublevalue-指定元素的值
BOOL型,说明设置是否成功
SetElement(intnRow,intnCol,doublevalue)
if(nCol<
0||nCol>
=m_nNumColumns||nRow<
0||nRow>
//arrayboundserror
//badpointererror
m_pData[nCol+nRow*m_nNumColumns]=value;
double型,指定元素的值
doubleCMatrix:
GetElement(intnRow,intnCol)const
ASSERT(nCol>
=0&
&
nCol<
m_nNumColumns&
nRow>
nRow<
m_nNumRows);
//arrayboundserror
ASSERT(m_pData);
returnm_pData[nCol+nRow*m_nNumColumns];
//获取矩阵的列数
int型,矩阵的列数
intCMatrix:
GetNumColumns()const
returnm_nNumColumns;
//获取矩阵的行数
int型,矩阵的行数
GetNumRows()const
returnm_nNumRows;
//获取矩阵的数据
double型指针,指向矩阵各元素的数据缓冲区
double*CMatrix:
GetData()const
returnm_pData;
//获取指定行的向量
//2.double*pVector-指向向量中各元素的缓冲区
int型,向量中元素的个数,即矩阵的列数
GetRowVector(intnRow,double*pVector)const
if(pVector==NULL)
deletepVector;
pVector=newdouble[m_nNumColumns];
ASSERT(pVector!
=NULL);
pVector[j]=GetElement(nRow,j);
//获取指定列的向量
//1.intnCols-指定的矩阵列数
int型,向量中元素的个数,即矩阵的行数
GetColVector(intnCol,double*pVector)const
pVector=newdouble[m_nNumRows];
pVector[i]=GetElement(i,nCol);
//重载运算符=,给矩阵赋值
other-用于给矩阵赋值的源矩阵
CMatrix型的引用,所引用的矩阵与other相等
CMatrix&
CMatrix:
operator=(constCMatrix&
if(&
other!
=this)
BOOLbSuccess=Init(other.GetNumRows(),other.GetNumColumns());
ASSERT(bSuccess);
//copythepointer
memcpy(m_pData,other.m_pData,sizeof(double)*m_nNumColumns*m_nNumRows);
//finallyreturnareferencetoourselves
return*this;
//重载运算符==,判断矩阵是否相等
other-用于比较的矩阵
BOOL型,两个矩阵相等则为TRUE,否则为FALSE
operator==(constCMatrix&
other)const
//首先检查行列数是否相等
if(m_nNumColumns!
=other.GetNumColumns()||m_nNumRows!
=other.GetNumRows())
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 误差 理论 测量 课程设计 实验 报告 讲解