# MATLAB: How to fit a polynomial with inequality constraints on the coefficients

## MATLAB: How to fit a polynomial with inequality constraints on the coefficients

constraintscurve fitting

I am trying to fit some data to the functional form:
f(x)=a(1)*exp(a(2)*x)+a(3)*(x^2)+a(4)*x-a(1)
I want to:
1. force a(1)*a(2)+a(4) to have a maximum value of 10
2. force f(x) to be positive at all values of x>0
I was trying to use lsqcurvefit, but it seems the function does not allow inequality constraints.
``x_data=[1.264000000000002.040000000000003.544000000000004.760000000000006.260000000000007.6440000000000011.772000000000013.688000000000018.368000000000018.3680000000000]y_data=[8.3600380000000014.000604000000032.591938000000047.097172000000050.773364000000046.991136000000041.142866000000037.619300000000039.491840000000039.0617800000000]``
Thanks!

#### Best Answer

• I enclose a file of code that attempts to find a good solution. If you run it a few times you will get different solutions, probably including some with a residue in the 1E-12 range, which is pretty much numeric noise considering the calculations.
I ran the minimization further through some code I wrote. To my surprise, I found a number of points where the numeric residue is exactly 0, indicating a perfect fit after all of the round-off issues. There are wide range of values that occurs for: a rectangular area in a(1) and a(2), and the extension in a(3) might possibly be quantized a bit. The only correlation that shows up is that a(3) and a(4) taken together form narrow-ish straight line instead of filling a volume.
The attached .mat includes a variable Q5A that lists over 800 points where the residue was 0.