How to put a fit condition such that the fitted curve is not above the fitted data (Fit<Fitted Data)?
조회 수: 3 (최근 30일)
이전 댓글 표시
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
채택된 답변
Torsten
2023년 1월 27일
이동: Torsten
2023년 1월 27일
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
Torsten
2023년 2월 8일
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);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!