Fitting data in a non-linear function with constraints

4 次查看(过去 30 天)
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!!!
  13 个评论
Matt J
Matt J 2018-7-24
Well (1) and (4) look impossible to satisfy simultaneously. I assume the f'() is the derivative with respect to x2, not x1. If so, then using (1) we can compute the form of f'() explicitly
y'(x1,x2=1) = (a/x1)^2*B(1)*B'(1)
There is no way the right hand side can equal 1 independently of x1, as demanded by constraint (4).
Vogel
Vogel 2018-7-25
编辑:Vogel 2018-7-25
Yes, f' is the derivative respect x2 and I calculated it my self and applied the constraint. However, for complicated functions, it is an arduous task. I was wondering if there was a way for Matlab to do it during the fitting process.

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2018-7-24
编辑:Matt J 2018-7-24
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Thermal Analysis 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by