本文整理汇总了C++中DblMatrix::SolveLinearCramer方法的典型用法代码示例。如果您正苦于以下问题:C++ DblMatrix::SolveLinearCramer方法的具体用法?C++ DblMatrix::SolveLinearCramer怎么用?C++ DblMatrix::SolveLinearCramer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DblMatrix
的用法示例。
在下文中一共展示了DblMatrix::SolveLinearCramer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FitLine
// x given
int FitLine(const DblVector& PointsY, const DblVector& PointsX, double& a, double& b)
{
assert(PointsX.size()==PointsY.size());
DblMatrix S;
S.Assign(3, 2, 0.0);
for(unsigned int i=0; i<PointsX.size(); i++)
{
S[0][0] += PointsX[i] * PointsX[i];
S[0][1] += PointsX[i];
S[0][2] += PointsX[i] * PointsY[i];
S[1][2] += PointsY[i];
}
S[1][1] = (double)PointsX.size();
S.Diagonalize();
DblVector Solutions;
int Ret = S.SolveLinearCramer(Solutions);
if(Ret)
{
a = Solutions[0];
b = Solutions[1];
}
else std::cout << "Error in line fitting" << std::endl;
return Ret;
}
示例2: FitParabola
// x given
int FitParabola(const DblVector& PointsY, const DblVector& PointsX, double& a, double& b, double& c)
{
// fit parabola
assert(PointsX.size()==PointsY.size());
DblMatrix S;
S.Assign(4, 3, 0.0);
for(unsigned int i=0; i<PointsX.size(); i++)
{
S[0][0] += PointsX[i] * PointsX[i] * PointsX[i] * PointsX[i];
S[0][1] += PointsX[i] * PointsX[i] * PointsX[i];
S[0][2] += PointsX[i] * PointsX[i];
S[0][3] += PointsX[i] * PointsX[i] * PointsY[i];
S[1][2] += PointsX[i];
S[1][3] += PointsX[i] * PointsY[i];
S[2][3] += PointsY[i];
}
S[1][1] = S[0][2];
S[2][2] = (double)PointsX.size();
S.Diagonalize();
DblVector Solutions;
int Ret = S.SolveLinearCramer(Solutions);
if(Ret==-1) return -1;
else
{
a = Solutions[0];
b = Solutions[1];
c = Solutions[2];
}
return Ret;
}
示例3: FitQuadraticSurface
// fit a two dimensional quadratic surface
int FitQuadraticSurface(const DblVector& PX, const DblVector& PY,
const DblVector& PZ, DblVector& Parameters)
{
// fit parabola
assert(PX.size()==PY.size());
DblMatrix S;
S.Assign(7, 6, 0.0);
for(unsigned int i=0; i<PX.size(); i++)
{
double X2 = PX[i] * PX[i];
double Y2 = PY[i] * PY[i];
double X3 = X2 * PX[i];
double Y3 = Y2 * PY[i];
double X4 = X3 * PX[i];
double Y4 = Y3 * PY[i];
S[0][1] += PY[i];
S[1][1] += Y2;
S[0][2] += PX[i];
S[1][2] += PX[i]*PY[i];
S[2][2] += X2;
S[0][3] += PX[i]*PY[i];
S[1][3] += PX[i]*Y2;
S[2][3] += X2*PY[i];
S[3][3] += X2*Y2;
S[0][4] += Y2;
S[1][4] += Y3;
S[2][4] += PX[i]*Y2;
S[3][4] += PX[i]*Y3;
S[4][4] += Y4;
S[0][5] += X2;
S[1][5] += X2*PY[i];
S[2][5] += X3;
S[3][5] += X3*PY[i];
S[4][5] += X2*Y2;
S[5][5] += X4;
// function values
S[0][6]+=PZ[i];
S[1][6]+=PY[i]*PZ[i];
S[2][6]+=PX[i]*PZ[i];
S[3][6]+=PX[i]*PY[i]*PZ[i];
S[4][6]+=Y2*PZ[i];
S[5][6]+=X2*PZ[i];
}
S[0][0] = (double)PX.size();
S.Diagonalize();
return S.SolveLinearCramer(Parameters);
}