水准网平差c++代码.docx
《水准网平差c++代码.docx》由会员分享,可在线阅读,更多相关《水准网平差c++代码.docx(25页珍藏版)》请在冰豆网上搜索。
水准网平差c++代码
水准平差网
结果
#include
#definemax50
Usingnamespacestd;
ClassCMatrix
{
public:
CMatrix(){row=0;column=0;};//默构造函数认认认认认
CMatrix(inti,intj){row=i;column=j;}//构造函数一
CMatrix(constCMatrix&m);//认制构造函数
~CMatrix(void){/*cout<<"认认认认认认认认认认认使用,矩所占空以放:
"<CMatrix&operator=(constCMatrix&m);//认认运算符booloperator==(constCMatrix&m);//比括运算符认认认认booloperator!=(constCMatrix&m);//比括运算符认认认认CMatrixoperator+(constCMatrix&m);//加运算符CMatrixoperator-(constCMatrix&m);//减运算符CMatrix&operator+=(constCMatrix&m);//自加运算符CMatrix&operator-=(constCMatrix&m);//自减运算符CMatrixoperator-();//取数认认CMatrix&operator*(constCMatrix&m);//乘法运算符voidinput();//认认入矩voidoutputMatrix();//认认认认出矩voidsetValue(introw,intcolumn,doublevalue){A[row-1][column-1]=value;}//认置(i,j)的认doublegetValue(introw,intcolumn)const{returnA[row-1][column-1];}//认认置行、列的voidsetRow(constinti){row=i;}intgetRow()const{returnrow;}voidsetColunm(constinti){column=i;}intgetColumn()const{returncolumn;}CMatrix&change(inti,intj);//交矩的行认认认认认CMatrix&transpose();//矩置认认认CMatrix&inverse();//矩求逆认认认voidfind(int&f)const;//判断矩是否可用于迭代求解认认认认认认认认认认认认friendvoidjocabi(constCMatrix&a);//迭代求解voidlzys();//列主元素法求解voidsolve();//可逆性矩求解认认认认认认voidqxnh();//曲合认认认private://成量认认认doubleA[max][max];introw;//行intcolumn;//列};voidCMatrix::input()//认入{cout<<"认认认认认认认始入矩:"<inti,j;doublez;for(i=0;i{cout<<"认认入第"<认认"<for(j=0;j{cin>>z;A[i][j]=z;}}cout<};CMatrix::CMatrix(constCMatrix&m)//认制构造函数{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j];};CMatrix&CMatrix::operator=(constCMatrix&m)//认认运算符{inti,j;for(i=0;i{for(j=0;jA[i][j]=m.A[i][j];}return*this;};boolCMatrix::operator==(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=1)returntrue;elsereturnfalse;};boolCMatrix::operator!=(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=0)returntrue;elsereturnfalse;};CMatrixCMatrix::operator+(constCMatrix&m)//加运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]+=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrixCMatrix::operator-(constCMatrix&m)//减运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
CMatrix&operator=(constCMatrix&m);//认认运算符
booloperator==(constCMatrix&m);//比括运算符认认认认
booloperator!
=(constCMatrix&m);//比括运算符认认认认
CMatrixoperator+(constCMatrix&m);//加运算符
CMatrixoperator-(constCMatrix&m);//减运算符
CMatrix&operator+=(constCMatrix&m);//自加运算符
CMatrix&operator-=(constCMatrix&m);//自减运算符
CMatrixoperator-();//取数认认
CMatrix&operator*(constCMatrix&m);//乘法运算符
voidinput();//认认入矩
voidoutputMatrix();//认认认认出矩
voidsetValue(introw,intcolumn,doublevalue){A[row-1][column-1]=value;}//认置(i,j)的认
doublegetValue(introw,intcolumn)const{returnA[row-1][column-1];}//认认置行、列的
voidsetRow(constinti){row=i;}
intgetRow()const{returnrow;}
voidsetColunm(constinti){column=i;}
intgetColumn()const{returncolumn;}
CMatrix&change(inti,intj);//交矩的行认认认认认
CMatrix&transpose();//矩置认认认
CMatrix&inverse();//矩求逆认认认
voidfind(int&f)const;//判断矩是否可用于迭代求解认认认认认认认认认认认认
friendvoidjocabi(constCMatrix&a);//迭代求解
voidlzys();//列主元素法求解
voidsolve();//可逆性矩求解认认认认认认
voidqxnh();//曲合认认认
private:
//成量认认认
doubleA[max][max];
introw;//行
intcolumn;//列
};
voidCMatrix:
:
input()//认入
{cout<<"认认认认认认认始入矩:
"<inti,j;doublez;for(i=0;i{cout<<"认认入第"<认认"<for(j=0;j{cin>>z;A[i][j]=z;}}cout<};CMatrix::CMatrix(constCMatrix&m)//认制构造函数{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j];};CMatrix&CMatrix::operator=(constCMatrix&m)//认认运算符{inti,j;for(i=0;i{for(j=0;jA[i][j]=m.A[i][j];}return*this;};boolCMatrix::operator==(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=1)returntrue;elsereturnfalse;};boolCMatrix::operator!=(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=0)returntrue;elsereturnfalse;};CMatrixCMatrix::operator+(constCMatrix&m)//加运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]+=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrixCMatrix::operator-(constCMatrix&m)//减运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
inti,j;
doublez;
for(i=0;i{cout<<"认认入第"<认认"<for(j=0;j{cin>>z;A[i][j]=z;}}cout<};CMatrix::CMatrix(constCMatrix&m)//认制构造函数{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j];};CMatrix&CMatrix::operator=(constCMatrix&m)//认认运算符{inti,j;for(i=0;i{for(j=0;jA[i][j]=m.A[i][j];}return*this;};boolCMatrix::operator==(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=1)returntrue;elsereturnfalse;};boolCMatrix::operator!=(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=0)returntrue;elsereturnfalse;};CMatrixCMatrix::operator+(constCMatrix&m)//加运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]+=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrixCMatrix::operator-(constCMatrix&m)//减运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
{cout<<"认认入第"<
认认"<for(j=0;j{cin>>z;A[i][j]=z;}}cout<};CMatrix::CMatrix(constCMatrix&m)//认制构造函数{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j];};CMatrix&CMatrix::operator=(constCMatrix&m)//认认运算符{inti,j;for(i=0;i{for(j=0;jA[i][j]=m.A[i][j];}return*this;};boolCMatrix::operator==(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=1)returntrue;elsereturnfalse;};boolCMatrix::operator!=(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=0)returntrue;elsereturnfalse;};CMatrixCMatrix::operator+(constCMatrix&m)//加运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]+=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrixCMatrix::operator-(constCMatrix&m)//减运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
for(j=0;j{cin>>z;A[i][j]=z;}}cout<};CMatrix::CMatrix(constCMatrix&m)//认制构造函数{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j];};CMatrix&CMatrix::operator=(constCMatrix&m)//认认运算符{inti,j;for(i=0;i{for(j=0;jA[i][j]=m.A[i][j];}return*this;};boolCMatrix::operator==(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=1)returntrue;elsereturnfalse;};boolCMatrix::operator!=(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=0)returntrue;elsereturnfalse;};CMatrixCMatrix::operator+(constCMatrix&m)//加运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]+=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrixCMatrix::operator-(constCMatrix&m)//减运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
{cin>>z;
A[i][j]=z;
}
cout<};CMatrix::CMatrix(constCMatrix&m)//认制构造函数{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j];};CMatrix&CMatrix::operator=(constCMatrix&m)//认认运算符{inti,j;for(i=0;i{for(j=0;jA[i][j]=m.A[i][j];}return*this;};boolCMatrix::operator==(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=1)returntrue;elsereturnfalse;};boolCMatrix::operator!=(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=0)returntrue;elsereturnfalse;};CMatrixCMatrix::operator+(constCMatrix&m)//加运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]+=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrixCMatrix::operator-(constCMatrix&m)//减运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
CMatrix:
CMatrix(constCMatrix&m)//认制构造函数{inti,j;
for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j];};CMatrix&CMatrix::operator=(constCMatrix&m)//认认运算符{inti,j;for(i=0;i{for(j=0;jA[i][j]=m.A[i][j];}return*this;};boolCMatrix::operator==(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=1)returntrue;elsereturnfalse;};boolCMatrix::operator!=(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=0)returntrue;elsereturnfalse;};CMatrixCMatrix::operator+(constCMatrix&m)//加运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]+=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrixCMatrix::operator-(constCMatrix&m)//减运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
for(j=0;jthis->A[i][j]=m.A[i][j];};CMatrix&CMatrix::operator=(constCMatrix&m)//认认运算符{inti,j;for(i=0;i{for(j=0;jA[i][j]=m.A[i][j];}return*this;};boolCMatrix::operator==(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=1)returntrue;elsereturnfalse;};boolCMatrix::operator!=(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=0)returntrue;elsereturnfalse;};CMatrixCMatrix::operator+(constCMatrix&m)//加运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]+=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrixCMatrix::operator-(constCMatrix&m)//减运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
this->A[i][j]=m.A[i][j];};
CMatrix&CMatrix:
operator=(constCMatrix&m)//认认运算符{
for(i=0;i{for(j=0;jA[i][j]=m.A[i][j];}return*this;};boolCMatrix::operator==(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=1)returntrue;elsereturnfalse;};boolCMatrix::operator!=(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=0)returntrue;elsereturnfalse;};CMatrixCMatrix::operator+(constCMatrix&m)//加运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]+=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrixCMatrix::operator-(constCMatrix&m)//减运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
for(j=0;jA[i][j]=m.A[i][j];}return*this;};boolCMatrix::operator==(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=1)returntrue;elsereturnfalse;};boolCMatrix::operator!=(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=0)returntrue;elsereturnfalse;};CMatrixCMatrix::operator+(constCMatrix&m)//加运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]+=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrixCMatrix::operator-(constCMatrix&m)//减运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
A[i][j]=m.A[i][j];
return*this;
boolCMatrix:
operator==(constCMatrix&m)//比括运算符认认认认{inti,j,k;
for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=1)returntrue;elsereturnfalse;};boolCMatrix::operator!=(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=0)returntrue;elsereturnfalse;};CMatrixCMatrix::operator+(constCMatrix&m)//加运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]+=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrixCMatrix::operator-(constCMatrix&m)//减运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=1)returntrue;elsereturnfalse;};boolCMatrix::operator!=(constCMatrix&m)//比括运算符认认认认{inti,j,k;for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=0)returntrue;elsereturnfalse;};CMatrixCMatrix::operator+(constCMatrix&m)//加运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]+=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrixCMatrix::operator-(constCMatrix&m)//减运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
if(this->A[i][j]=m.A[i][j])k=1;
elsek=0;
if(k=1)returntrue;
elsereturnfalse;
operator!
=(constCMatrix&m)//比括运算符认认认认{inti,j,k;
for(i=0;i{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=0)returntrue;elsereturnfalse;};CMatrixCMatrix::operator+(constCMatrix&m)//加运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]+=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrixCMatrix::operator-(constCMatrix&m)//减运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
{for(j=0;jif(this->A[i][j]=m.A[i][j])k=1;elsek=0;}if(k=0)returntrue;elsereturnfalse;};CMatrixCMatrix::operator+(constCMatrix&m)//加运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]+=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrixCMatrix::operator-(constCMatrix&m)//减运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
if(k=0)returntrue;
CMatrixCMatrix:
operator+(constCMatrix&m)//加运算符{inti,j;
if((this->row==m.row)&&(this->column==m.column))
{for(i=0;ifor(j=0;jthis->A[i][j]+=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrixCMatrix::operator-(constCMatrix&m)//减运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
for(j=0;jthis->A[i][j]+=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrixCMatrix::operator-(constCMatrix&m)//减运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
this->A[i][j]+=m.A[i][j];
else{cout<<"此两矩不能相加,:
认认认认认认认认认认"<return*this;};CMatrixCMatrix::operator-(constCMatrix&m)//减运算符{inti,j;if((this->row==m.row)&&(this->column==m.column)){for(i=0;ifor(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
operator-(constCMatrix&m)//减运算符
{inti,j;
{for(i=0;ifor(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
for(j=0;jthis->A[i][j]-=m.A[i][j];}else{cout<<"此两矩不能相加,:认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
this->A[i][j]-=m.A[i][j];
认认认认认认认认认认"<return*this;};CMatrix&CMatrix::operator+=(constCMatrix&m)//自加运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
operator+=(constCMatrix&m)//自加运算符
for(i=0;ifor(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
for(j=0;jthis->A[i][j]=2*m.A[i][j];return*this;};CMatrix&CMatrix::operator-=(constCMatrix&m)//自减运算符{inti,j;for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
this->A[i][j]=2*m.A[i][j];
operator-=(constCMatrix&m)//自减运算符
for(i=0;ifor(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
for(j=0;jthis->A[i][j]=m.A[i][j]-m.A[i][j];return*this;};voidCMatrix::find(int&f)const{inti;for(i=0;irow;i++)if(this->A[i][i]!=0)f=1;elsef=0;};CMatrixCMatrix::operator-()//取数认认{inti,j;for(i=0;irow;i++)for(j=0;jcolumn;j++)this->A[i][j]=-this->A[i][j];return*this;};CMatrix&CMatrix::operator*(constCMatrix&m)//乘法运算符{inti,j,t;CMatrixn;if(this->column==m.row){for(i=0;irow;i++)for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
this->A[i][j]=m.A[i][j]-m.A[i][j];
find(int&f)const{inti;
for(i=0;irow;i++)
if(this->A[i][i]!
=0)f=1;
elsef=0;
operator-()//取数认认
for(j=0;jcolumn;j++)
this->A[i][j]=-this->A[i][j];
operator*(constCMatrix&m)//乘法运算符
{inti,j,t;
CMatrixn;
if(this->column==m.row)
for(j=0;j{doublesum=0.0;for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
{doublesum=0.0;
for(t=0;tsum+=this->A[i][t]*m.A[t][j];n.A[i][j]=sum;}}else{cerr<<"此两矩不能相乘,:认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
sum+=this->A[i][t]*m.A[t][j];
n.A[i][j]=sum;
else{cerr<<"此两矩不能相乘,:
认认认认认认认认认认"<(1);}returnn;};voidCMatrix::outputMatrix()//认认认认出矩{inti,j;for(i=1;i<=row;i++){for(j=1;j<=column;j++)cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
(1);}
returnn;
outputMatrix()//认认认认出矩
for(i=1;i<=row;i++)
{for(j=1;j<=column;j++)
cout<cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
cout<}};CMatrix&CMatrix::transpose()//矩置认认认{inti,j;CMatrixm(this->column,this->row);for(i=0;irow;i++)for(j=0;jcolumn;j++){m.A[j][i]=this->A[i][j];}returnm;};voidjocabi(constCMatrix&a)//高斯迭代求解{intf=1;a.find(f);if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
transpose()//矩置认认认
CMatrixm(this->column,this->row);
{m.A[j][i]=this->A[i][j];}
returnm;
voidjocabi(constCMatrix&a)//高斯迭代求解
{intf=1;
a.find(f);
if(f==0){cerr<<"认认认认认认认认认认认认矩不足迭代求解条件:
"<(1);}else{CMatrixx,w;x.setColunm(1);x.setRow(a.getColumn());w.setColunm(1);w.setRow(a.getColumn());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}for(i=1;i<=x.row;i++){cout<<"认认入X"<认认";cin>>z;x.setValue(i,1,z);}i=1;while(i<=20){intj,k;for(j=1;j<=x.row;j++){doublesum=0.0;for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
else
CMatrixx,w;
x.setColunm
(1);
x.setRow(a.getColumn());
w.setColunm
w.setRow(a.getColumn());inti;
for(i=1;i<=x.row;i++)
{cout<<"认认认认认入等式右的第"<
认认";
cin>>z;
w.A[i-1][0]=z;
{cout<<"认认入X"<
x.setValue(i,1,z);
i=1;
while(i<=20)
{intj,k;
for(j=1;j<=x.row;j++)
for(k=1;k{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}for(k=j+1;k<=x.row;k++){sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}sum+=w.A[j-1][0];x.A[j-1][0]=sum/a.A[j-1][j-1];}i++;}for(i=1;i<=x.row;i++)cout<<"X"<}};doublejdz(doublea)//认认认{if(a>0.0)returna;elsereturn-a;};CMatrix&CMatrix::change(inti,intj)//交矩的行认认认认认{intk;doublez;for(k=1;k<=this->column;k++){z=A[i-1][k-1];A[i-1][k-1]=A[j-1][k-1];A[j-1][k-1]=z;}return*this;};voidCMatrix::lzys()//列主元素法求解{CMatrixx,w;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());inti;doublez;for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
{sum=sum-(a.A[j-1][k-1])*(x.A[k-1][0]);}
for(k=j+1;k<=x.row;k++)
sum+=w.A[j-1][0];
x.A[j-1][0]=sum/a.A[j-1][j-1];
i++;
cout<<"X"<
doublejdz(doublea)//认认认
{if(a>0.0)returna;elsereturn-a;
change(inti,intj)//交矩的行认认认认认
{intk;
for(k=1;k<=this->column;k++)
{z=A[i-1][k-1];
A[i-1][k-1]=A[j-1][k-1];
A[j-1][k-1]=z;
lzys()//列主元素法求解
{CMatrixx,w;
x.setRow(getColumn());
w.setRow(getColumn());inti;
for(i=0;i{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
{for(intj=0;jw.A[i][j]=0.0;}for(i=1;i<=x.row;i++)x.setValue(i,1,0.0);for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
w.A[i][j]=0.0;
x.setValue(i,1,0.0);
i=0;
while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
{intj,t,h=i;
for(j=i;j{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
{if(jdz(A[j][i])this->change(i+1,h+1);w.change(i+1,1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
this->change(i+1,h+1);
w.change(i+1,1);
for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
{doublek;
k=A[j][i]/A[i][i];
for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩的方程有无解:认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
A[j][t]=A[j][t]-k*A[i][t];
w.A[j][0]=w.A[j][0]-k*w.A[i][0];
if(this->A[row-1][column-1]==0)
{cerr<<"此矩的方程有无解:
认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}w.A[j][0]=w.A[j][0]-k*w.A[i][0];}i--;}intj;for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
i=column-1;
while(i>0)
{intj,t;
for(j=i-1;j>=0;j--)
for(t=i;t>j;t--)
{A[j][t]=A[j][t]-k*A[i][t];}
i--;
intj;
for(j=0;j{x.A[j][0]=w.A[j][0]/this->A[j][j];}for(i=1;i<=x.row;i++)cout<<"X"<};CMatrix&CMatrix::inverse()//矩求逆认认认{if(this->row!=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
x.A[j][0]=w.A[j][0]/this->A[j][j];
inverse()//矩求逆认认认
{if(this->row!
=this->column){cerr<<"认认认认认认认认认认矩不符合求逆条件:
"<(1);}else{CMatrixw;w.setColunm(this->getRow());w.setRow(getColumn());inti;for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
CMatrixw;
w.setColunm(this->getRow());w.setRow(getColumn());
inti;
for(i=0;i{for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
for(intj=0;j{w.A[i][j]=0.0;}w.A[i][i]=1;}i=0;while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
{w.A[i][j]=0.0;}
w.A[i][i]=1;
while(i{intj,t,h=i;for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
for(j=i;j{if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
if(jdz(A[j][i])h=j+1;}this->change(i+1,h+1);w.change(i+1,h+1);for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
h=j+1;
w.change(i+1,h+1);
for(j=i+1;j{doublek;k=A[j][i]/A[i][i];for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
for(t=i;t{A[j][t]=A[j][t]-k*A[i][t];w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i++;}if(this->A[row-1][column-1]==0){cerr<<"此矩求逆不成功,其所的方程有无解:认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
w.A[j][t]=w.A[j][t]-k*w.A[i][t];
{cerr<<"此矩求逆不成功,其所的方程有无解:
认认认认认认认认认认认认认认认认认认认认"<(1);}i=column-1;while(i>0){intj,t;for(j=i-1;j>=0;j--){doublek;k=A[j][i]/A[i][i];for(t=i;t>j;t--){A[j][t]=A[j][t]-k*A[i][t];}for(t=column-1;t>=0;t--){w.A[j][t]=w.A[j][t]-k*w.A[i][t];}}i--;}intj,k;for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
for(t=column-1;t>=0;t--)
{w.A[j][t]=w.A[j][t]-k*w.A[i][t];}
intj,k;
for(j=0;j{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
{for(k=0;k{w.A[j][k]=w.A[j][k]/this->A[j][j];}this->A[j][j]=this->A[j][j]/this->A[j][j];}returnw;}};voidCMatrix::solve()//可逆性矩求解认认认认认认{CMatrixx,w,c;x.setColunm(1);x.setRow(getColumn());w.setColunm(1);w.setRow(getColumn());c.setColunm(getColumn());c.setRow(getRow());inti;doublez;for(i=1;i<=x.row;i++){cout<<"认认认认认入等式右的第"<认认";cin>>z;w.A[i-1][0]=z;}c.operator=(this->inverse());x.operator=(c.operator*(w));cout<<"求解果:认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
{w.A[j][k]=w.A[j][k]/this->A[j][j];}
this->A[j][j]=this->A[j][j]/this->A[j][j];
returnw;
solve()//可逆性矩求解认认认认认认
CMatrixx,w,c;
w.setRow(getColumn());
c.setColunm(getColumn());
c.setRow(getRow());
c.operator=(this->inverse());x.operator=(c.operator*(w));
cout<<"求解果:
认认认"<for(i=1;i<=x.row;i++)cout<<"X"<};voidCMatrix::qxnh()//曲合认认认{cout<<"用矩曲合:认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
qxnh()//曲合认认认
cout<<"用矩曲合:
认认认认认认"<inti,j,k,t;doublex,y;cout<<"认认认认认认认认入已知坐点的个数:";cin>>i;CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);for(j=1;j<=i;j++){cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
inti,j,k,t;
doublex,y;
cout<<"认认认认认认认认入已知坐点的个数:
";
cin>>i;
CMatrixa(i,1),g(i,i),w(i,1),c(i,i),q(i,i),p(i,i);
for(j=1;j<=i;j++)
{cout<<"认认入第"<";cin>>x>>y;w.A[j-1][0]=y;g.A[j-1][0]=1.0;for(k=1;k{g.setValue(j,k+1,1.0);for(t=1;t<=k;t++)g.A[j-1][k]*=x;}}c=g.transpose();q=c*g;p=q.inverse();w=c*w;a=p*w;cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
cin>>x>>y;
w.A[j-1][0]=y;
g.A[j-1][0]=1.0;
for(k=1;k
{g.setValue(j,k+1,1.0);
for(t=1;t<=k;t++)
g.A[j-1][k]*=x;
c=g.transpose();
q=c*g;
p=q.inverse();
w=c*w;
a=p*w;
cout<<"Y="<for(j=1;j{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
for(j=1;j
{cout<<'+'<<'('<for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
for(k=0;kcout<<"*x";}cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
cout<<"*x";
cout<cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
cout<<"1.求取其它点坐认0.退出"<while(1){cout<<"认认认:";cin>>k;switch(k){case1:{doublex,y,sum;cout<<"认认认认入待求点的横坐,x,:";cin>>x;y=a.A[0][0];for(j=1;j{sum=a.A[j][0];for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
while
(1)
{cout<<"认认认:
cin>>k;
switch(k)
{case1:
{doublex,y,sum;
cout<<"认认认认入待求点的横坐,x,:
cin>>x;
y=a.A[0][0];
{sum=a.A[j][0];
for(k=0;k{sum*=x;}y+=sum;}cout<<"认认认坐:y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
{sum*=x;}
y+=sum;
cout<<"认认认坐:
y="<}case0:{cerr<<"认认使用:"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
case0:
cerr<<"认认使用:
"<(1);break;}default:cout<<"认认认认认认认认有,:"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
break;
default:
cout<<"认认认认认认认认有,:
"<}}};structCElvDif{doublevalue;//认认认doubleweight;//认重longstartPoint;//起始点号认认longendPoint;//认认认点号};//水准点的认认认认structCLevelPoint{//高程平差=认高程认+高程改正数认认认认longindex;//水准点号认认doubleeleValue;//高程认doubledv;//高程改正数,初始化认认认认认认认认认0,boolisKnown;//是否已知点认认认认};classCElevationNet{public://成函数认认认CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数~CElevationNet(){};//析构函数voidinput();voidoutput();voidjsgc();intgetgz(){returnnumElvDif;}//返回数目认认认认认intgetzs(){returnnumPoints;}//返回点数认认认intgetys(){returnnumKnPoint;}//返回已知点数intgetws(){returnnumPoints-numKnPoint;}//返回未知点数doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认private://成量认认认intnumElvDif;//高差数认认intnumPoints;//控制网中点的数目认认认intnumKnPoint;//控制网中已知点的数目CElvDifedVec[max]
structCElvDif
doublevalue;//认认认
doubleweight;//认重
longstartPoint;//起始点号认认
longendPoint;//认认认点号
//水准点的认认认认
structCLevelPoint
{//高程平差=认高程认+高程改正数认认认认
longindex;//水准点号认认
doubleeleValue;//高程认
doubledv;//高程改正数,初始化认认认认认认认认认0,
boolisKnown;//是否已知点认认认认
classCElevationNet
//成函数认认认
CElevationNet(){numElvDif=0;numPoints=0;numKnPoint=0;};//构造函数
~CElevationNet(){};//析构函数voidinput();
voidoutput();
voidjsgc();
intgetgz(){returnnumElvDif;}//返回数目认认认认认
intgetzs(){returnnumPoints;}//返回点数认认认
intgetys(){returnnumKnPoint;}//返回已知点数
intgetws(){returnnumPoints-numKnPoint;}//返回未知点数
doublegeteleValue(inti){returnthis->lpVec[i-1].eleValue;}//认认得高程
longgetindex(inti){returnlpVec[i-1].index;}//返回高程点号认认
voidseteleValue(inti,doublevalue){lpVec[i-1].eleValue+=value;}//修改高程认
voidsetdv(inti,doublevalue){this->lpVec[i-1].dv=value;}//修改改正数
doublegetdv(inti){returnlpVec[i-1].dv;}//返回改正数
friendvoidxishu(CMatrix&B,CMatrix&X,CElevationNetA);//求取系数矩和未知点高程矩认认认认认认认认认
friendvoidquanzhen(CMatrix&Q,CElevationNetA);//求取认认
friendvoidl_zhen(CMatrix&l,CMatrix&L,CElevationNetA);//求取认认认L矩和认认l认
intnumElvDif;//高差数认认
intnumPoints;//控制网中点的数目认认认
intnumKnPoint;//控制网中已知点的数目
CElvDifedVec[max]
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1