How to put a fit condition such that the fitted curve is not above the fitted data (Fit<Fitted Data)?

2 visualizaciones (últimos 30 días)
Hello Matlab community,
I am a bit stuggling to understand if there is an easy way to implement the condition above! I am using the fittype function:
aFittype = fittype(expression)
and fitting an easy exponential decay. I tried using a weighting factor, to add a constraint on the fit, but it is not enough.
For physical reason, the exponential decay fitted would make more sense if its values would less than the fitted data. I am then subtracting this as a background.
Thank you for the suggestions!

Respuesta aceptada

Torsten
Torsten el 27 de En. de 2023
Movida: Torsten el 27 de En. de 2023
In each measurement point, add the constraint
y_measurement >= fun(x_measurement)
where "fun" is your exponential curve.
You will have to use "fmincon" instead of "fit" to incorporate the constraints either in matrix A and vector B or in function "nonlcon".
  4 comentarios
Torsten
Torsten el 8 de Feb. de 2023
fun = @(p) sum( ( p(1)*exp(-x/(8.618e-5*p(2))) - y ).^2 )
instead of
fun = @(p) sum((p(1)*exp(-x/(8.618e-5.*p(2))))-y)^2
and
c = difference;
ceq = [];
instead of
c = [];
ceq = sum(difference > 0);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by