How do I fit a curve to data while constraining both endpoints of the curve?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am currently optimizing models to fit phase equilibria diagrams. I understand how to use MATLAB to optimize the curve fit, however it is very important that the endpoints be fixed, as each endpoint represents a pure fluid, and the models must get pure fluid properties correct (and do when the parameter I am adjusting is set to zero). The rest of the points are a mixture of the two fluids and just need to be fit as close as possible, but it is these points that need to have the parameter I am adjusting fit to a non-zero number.
3 comentarios
Star Strider
el 29 de Abr. de 2015
The Peng-Robinson Equation of State postdated my college p-chem, so it’s new to me. I’m not exactly certain how you want to fit that model, but if you have the Optimization Toolbox, there are several constrained optimisation functions that would probably work. (The Global Optimization Toolbox adds genetic algorithms, simulated annealing and such, most if not all of which allow constraints.)
You could also include in your objective function, or preferably in an anonymous function that calls it, code that would constrain certain parameters and fit only the ones you want optimised. The anonymous function approach has the advantage of avoiding the need to change your objective function, and would allow you to set your chosen parameters to zero and fit the rest. This is a relatively routine procedure, and easy to code. I am not certain how it would affect any statistics you want to calculate from the fit (such as confidence intervals).
If you don’t have the Optimization Toolbox, there are some File Exchange contributions that appear to offer similar functionality. I will let you search to see if any are appropriate to your problem, since I have no experience with them.
I’m not listing this as an Answer, because it isn’t one.
Respuestas (1)
John D'Errico
el 29 de Abr. de 2015
Editada: John D'Errico
el 29 de Abr. de 2015
x = linspace(0,1,100);
y = sin(x*pi*3/2) + randn(size(x))/10;
slm = slmengine(x,y,'leftvalue',0,'rightvalue',-1,'knots',6,'plot','on','rightslope',0);
The fit looks quite nice. See that I was able to set either endpoint and the end point slope with no problems. There are many other things you can specify.
How about the end point values?
slmeval(0,slm,0)
ans =
0
slmeval(1,slm,0)
ans =
-1
slmeval(1,slm,1)
ans =
2.8386e-17
The last is as close as you will sometimes come to 0. I'll just call it close enough for government work.
Note that while sometimes (depending on your choice of constraints) SLM will need the optimization toolbox, the above call will work without that toolbox.
2 comentarios
John D'Errico
el 29 de Abr. de 2015
No. You cannot use a spline to estimate a parameter if you MUST use the model you have posed.
IF your goal is simply prediction, then a spline model is often a far better choice. It will give you a Y value for any X in the interval of fit.
IF your goal is to fit the model you have given, because you also need the parameters from that model for purposes other than prediction, then you need to use a nonlinear optimization tool, like fmincon. That tool is necessary because of the equality constraints at the end points.
The fact is however, that in the model you suggested, there are not that many parameters to estimate. If you will force it to go through two points, then you will lose two degrees of freedom. The model simply does not have sufficient flexibility to pass exactly through two points, and ALSO to fit the curve well.
Ver también
Categorías
Más información sobre Thermodynamics and Heat Transfer en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!