Ask Your Question

Revision history [back]

My data are 9 points (0,0,1) (1,0,3) (2,0,5) (0,1,4) , (1,1,8) (2,1,7) (0,2,7) (1,2,8) (2,2,8)

I want to solve z = M p where p=[ a b c] and a xi+ byi +c =zi

 int main(int argc, char* argv[])
{

Mat z=(Mat_<double>(9,1) << 1, 3, 5, 4, 8, 7, 7, 8, 8);
Mat m=(Mat_<double>(9,3) << 0, 0 ,1,1,0 ,1,2 ,0 ,1,0 ,1 ,1,1 ,1, 2,2, 1, 1,0,2, 1,1,2,1,2, 2, 1);
SVD s(m);
Mat dst;
s.backSubst(z,dst);
cout<< dst;

return 0;
}

and it gives answer :

[1.249999999999997; 2.249999999999998; 2.000000000000005]

I hope it will help you

My data are 9 points (0,0,1) (1,0,3) (2,0,5) (0,1,4) , (1,1,8) (2,1,7) (0,2,7) (1,2,8) (2,2,8)

I want to solve z = M p where p=[ a b c] and a xi+ byi +c =zi

 int main(int argc, char* argv[])
{

Mat z=(Mat_<double>(9,1) << 1, 3, 5, 4, 8, 7, 7, 8, 8);
Mat m=(Mat_<double>(9,3) << 0, 0 ,1,1,0 ,1,2 ,1/**/,1,0 ,1/**/,2 ,0 ,1,0 ,1/**/,0 ,1 ,1,1 ,1/**/,1 ,1, 2,2, 1/**/, 2, 1, 1,0,2, 1,1,2,1,2, 1/**/, 0,2, 1/**/, 1,2,1/**/, 2, 2, 1);
SVD s(m);
Mat dst;
Mat singularValue;
s.backSubst(z,dst);
cout<< dst;

return 0;
}
cout<<"Solution z= m dst"<< dst<<endl;
s.compute(m,singularValue);
cout<<"singular value :"<<singularValue<<endl;
Mat mp=(Mat_<double>(9,4) << 0, 0 ,1,1/**/,1,0 ,3,1/**/,2 ,0 ,5,1/**/,0 ,1 ,4,1/**/,1 ,1, 8,1/**/,2, 1, 7,1/**/, 0, 2, 7,1/**/, 1,2,8,1/**/, 2, 2, 8,1);
SVD s2(mp);
Mat a;
s2.solveZ(mp,a);
cout<<"Solution mp *a =0"<<a<<endl;

and it gives answer :

[1.249999999999997;

Solution z= m dst[1.333333333333331;
 2.249999999999998;
2.333333333333332;
 2.000000000000005]

2.000000000000002] singular value :[5.592252381884617; 2.449489742783178; 1.314044632919994] Solution mp *a =0[0.3330915074747192; 0.6439188217126393; -0.2753503146060172; 0.6313484005989033]

I hope it will help you