Fitting data in a non-linear function with constraints
Afficher commentaires plus anciens
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 commentaires
Matt J
le 19 Juil 2018
I don't understand (1) and (2). What is "y"? And since your only unknowns are a,b,c,d, & z, how can there be constraints on anything else?
Matt J
le 20 Juil 2018
So you want y to be bounded between 0 and 1 for 0<=x1<=1 and 0<=x2<=1?
Vogel
le 20 Juil 2018
Vogel
le 23 Juil 2018
The function
y = exp((-a./x1).*(b.*x2.^3 + c.*x2.^2 + d.*x2 + f)) - exp((p./x1).*(q.*x2.^3 + r.*x2.^2 + s.*x2 + t));
doesn't look like a very physical model. If you don't already have a physical model, why is this difference of exponentials a compelling choice for a hypothesized model? Why not instead use some kind of sigmoid (e.g., arctan()) which is inherently bounded?
If it is a known physical model, why doesn't the existing physics theory that it came from tell you for what range of parameters the function is inherently bounded?
Matt J
le 24 Juil 2018
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).
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Get Started with Curve Fitting Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
