2a + 2b + 3c = 15
3a + 5b + 2c = 19
5a + 3b + 3c = 20
OpenCVのMatの逆行列を計算する関数を使って,
#include <opencv2/opencv.hpp> using namespace cv; using std::cout; using std::endl; int main() { Mat matA = (Mat_<float>(3,3) << 2, 2, 3, 3, 5, 2, 5, 3, 3); Mat matB = (Mat_<float>(3,1) << 15, 19, 20); Mat matX(3, 1, CV_32FC1); matX = matA.inv()*matB; cout << "a=" << matX.at<float>(0) << endl; cout << "b=" << matX.at<float>(1) << endl; cout << "c=" << matX.at<float>(2) << endl; }
ちゃんと,a=1, b=2, c=3の解が出る.