MATLAB: Fitting data in a non-linear function with constraints

boundary conditionsconstraintsfittingnon-linear

Hello,
I need to fit some data (y_data = f(x1_data,x2_data)) in a certain function. I used 'objfcn', but I have to apply some boundary conditions (i.e. the curve must intersect a certain point, the second derivative must be positive, etc.).
Does anybody know if there is a way to do it with Matlab? (Well, I could artificially add the desired points to my data, but I guess this is not cientifically correct?)
I also checked lsqcurvefit, but, if I understood it well, you can only specify the ranges of the coefficients, but not the data.
In the following you find the case I need to solve, just in case my question was not clear.
Thank you in advance!
===================================================================================
I would like to fit some data in the following equation:
y_data = f(x1_data, x2_data)
Where f(x1, x2) = e^((a*x2^3 + b*x2^2 + c*x2 + d )*(-1/x1)) – z
and a,b,c,d and z are the coefficients to be determined.
There are many constraints:
1) 0 =< x2 =< 1
2) 0 =< y =< 1
(My data ranges from x2 = [0.3, 0.95] and y = [0.02,0.95])
3) x2 = 0 –> f = 0
(This is way I added the coefficient z. It is a kind of correction, since e^0 = 1, and there is otherwise no way to make it 0).
4) x2 = 1 –> f = 1
5) x2 = 1 –> f' = 1
6) x2 = 0 –> f'' > 0
To accomplish constraints 3, 4 and 5 I resolved the equations, so that dependent coefficients are obtained:
z = -e^(-d/x1)
c = -x1/(1+e^(-d/x1)) – 3*a -2*b
I tried to solve it as follows:
objfcn = @(b,x1,x2) exp(-1./x1.*( b(1).*x2.^3 + b(2).*x2.^2 + (-x1./(1+exp(b(3).*(-1./(x1))))-3*b(1)-2*b(2)).*x2 + b(3))) - exp(b(3).*(-1./(x1)));
[B,resnorm] = fminsearch(@(b) norm(y - objfcn(b,x1,x2)), [1;1;1]);
However, I don't know how to implement 1, 2 and 6.
*Here my questions:
– Is it possible to introduce constraints 3,4 and 5 with a Matlab function, instead of solving equations?
– Do you know if it is possible to apply constraints 1,2 and 6?*
Thanks!!!

Best Answer

I need to find B(x2). However, there are not physical models to determine it, so here I just looked for mathematical functions that permits implementing all the boundary conditions.
If you aren't committed to a particular model, it might be useful for you to look at SLM. It allows you to do spline fitting subject to various boundary conditions and montononicity conditions both on the function and on slope.
Related Question