#include <stdio.h>
#include "cv.h"
#include "cvtypes.h"
#include "leastsquare.h"

void printMat(CvMat* mat) {
  int i,j;
  float* danger;
  danger = mat->data.fl;
  for (i = 0; i < mat->rows; i++) {
    for (j = 0; j < mat->cols; j++) {
      printf("%3.2f ", danger[i*mat->cols + j]);
    }
    printf("\n");
  }
}

void testMatMul() {
  int i;
  
  CvMat A;
  CvMat B;
  
  A = cvMat(3, 3, CV_32F, 0);
  B = cvMat(3, 3, CV_32F, 0);
  
  cvmAlloc(&A);
  cvmAlloc(&B);
  
  for (i = 0; i < 9; i++) {
    cvmSet(&A, i / 3, i % 3, (double) i);
  }
  
  cvmMul(&A,&A,&B);
  printMat(&A);
  printMat(&B);
}

#define LEASTSQUARE_TEST_SIZE 6
void testLeastSquare() {
  float data_xx[LEASTSQUARE_TEST_SIZE] = { 1.0, 2.0, 4.0, 5.0, 6.0, 7.0 };
  float data_yy[LEASTSQUARE_TEST_SIZE] = { 10.0, 6.0, 3.0, 4.0, 6.0, 10.0 };
  float a, b, c;
  
  compute_least_square(LEASTSQUARE_TEST_SIZE, data_xx, data_yy,
			&a, &b, &c);
  
  printf("a=%3.2f  b=%3.2f  c=%3.2f\n", a, b, c);
}

int main() {
  testLeastSquare();
  return 0;
}
