1 | initial version |
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
2 | No.2 Revision |
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;
I hope it will help you