0

I have scoured Octave resources, pdfs on optimization, and many of the questions here, but I can't seem to find or understand the right solution. I'm trying to find a corrective solution to move a group of data points to match closely another set. The equation used is a quadratic with a cross term, i.e. ax^2 +bx +c + d*y = x', where x is from one data set and x' is from another. There is a similar equation for the y coordinate.

I make the x and y values fixed from the data, and am trying to optimize the coefficients to minimize the square sum error between all the points. For now, I'm just trying to minimize the difference between x and x', via ax^2 +bx +c + d*y - x' = 0. I will try to do a square sum of all the equations later, unless someone here can help me with that as well.

I've tried using fminunc and fminsearch, both having and error after a few iterations due to matrix sizes. I don't think these solutions like having more equations than variables. I do not think qp or glpk are useful solutions.

Here is an example of my system of equations I'm trying to minimize. Future iterations may have as many as 32 equations, but the same number of vairables/coefficients.

function zer = fcn(coeff)
zer = zeros(18,1);
   zer(1) = coeff(1)*19.338458^2 + coeff(2)*19.338458 + coeff(3) + coeff(4)*17.806945 - 23.200000;
   zer(2) = coeff(1)*-0.146987^2 + coeff(2)*-0.146987 + coeff(3) + coeff(4)*2.273490 - 2.900000;
   zer(3) = coeff(1)*-18.333520^2 + coeff(2)*-18.333520 + coeff(3) + coeff(4)*-19.133048 - -15.700000;
   zer(4) = coeff(1)*-24.447818^2 + coeff(2)*-24.447818 + coeff(3) + coeff(4)*2.146905 - -21.700000;
   zer(5) = coeff(1)*0.363997^2 + coeff(2)*0.363997 + coeff(3) + coeff(4)*27.305928 - 3.500000;
   zer(6) = coeff(1)*15.042656^2 + coeff(2)*15.042656 + coeff(3) + coeff(4)*-15.456741 - 18.800000;
   zer(7) = coeff(1)*18.529375^2 + coeff(2)*18.529375 + coeff(3) + coeff(4)*1.046316 - 22.100000;
   zer(8) = coeff(1)*0.045810^2 + coeff(2)*0.045810 + coeff(3) + coeff(4)*-21.082700 - 3.300000;
   zer(9) = coeff(1)*-18.499911^2 + coeff(2)*-18.499911 + coeff(3) + coeff(4)*22.048530 - -15.700000;
   zer(10) = coeff(5)*17.806945^2 + coeff(6)*17.806945 + coeff(7) + coeff(8)*19.338458 - 16.000000;
   zer(11) = coeff(5)*2.273490^2 + coeff(6)*2.273490 + coeff(7) + coeff(8)*-0.146987 - 0.300000;
   zer(12) = coeff(5)*-19.133048^2 + coeff(6)*-19.133048 + coeff(7) + coeff(8)*-18.333520 - -21.400000;
   zer(13) = coeff(5)*2.146905^2 + coeff(6)*2.146905 + coeff(7) + coeff(8)*-24.447818 - 0.400000;
   zer(14) = coeff(5)*27.305928^2 + coeff(6)*27.305928 + coeff(7) + coeff(8)*0.363997 - 25.700000;
   zer(15) = coeff(5)*-15.456741^2 + coeff(6)*-15.456741 + coeff(7) + coeff(8)*15.042656 - -18.300000;
   zer(16) = coeff(5)*1.046316^2 + coeff(6)*1.046316 + coeff(7) + coeff(8)*18.529375 - -1.100000;
   zer(17) = coeff(5)*-21.082700^2 + coeff(6)*-21.082700 + coeff(7) + coeff(8)*0.045810 - -23.200000;
   zer(18) = coeff(5)*22.048530^2 + coeff(6)*22.048530 + coeff(7) + coeff(8)*-18.499911 - 20.200000;
endfunction
mhotkow
  • 11
  • 2
  • Looks to me like a linear regression problem. `x' `is the dependent variable and `x^2,x,y` are the independent variables (plus an intercept). Octave has several functions for linear regression. – Erwin Kalvelagen Jun 16 '21 at 16:36
  • I agree with Erwin. Write this as a matrix multiplication, then use `\\` to solve the system. – Cris Luengo Jun 16 '21 at 18:20
  • Okay, I'll try that. I was under the impression that it only worked if there was a perfect solution. – mhotkow Jun 16 '21 at 18:35

1 Answers1

0

Erwin and Cris in the comments are 100% correct.

All that needs to be done here is convert this into a matrix with a answer vector.

best_solution = Matrix\answer_vector;

It's embarrassing how much I overcomplicated the problem.

mhotkow
  • 11
  • 2