How to put a fit condition such that the fitted curve is not above the fitted data (Fit<Fitted Data)?
7 views (last 30 days)
Show older comments
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:
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!
0 Comments
Accepted Answer
Torsten
on 27 Jan 2023
Moved: Torsten
on 27 Jan 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 Comments
Torsten
on 8 Feb 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);
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!