- You can't ever fit your data "exactly" (in principle), unless you only have as many data points as you have free parameters, or if your data was generated from the model. And if you did, some types of simple optimizers may fail. You should look for a rootfinding algorithm if you have as many data points as parameters.
- It may be that your model is not appropriate, so you will never be able to match the "shape". Do you know indepedently that your proposed model should work (your data is very clean...was it generated from a model?)
- I'm not sure if this will help, but can you combine the offsets a-c into a 5th parameter f:
MATLAB Curve fitting with custom equation
조회 수: 526 (최근 30일)
이전 댓글 표시
Hello,
I have a data (x,y) points and I want to fit it with custom equation as y = a*(1-exp(-b*x))+c*(exp(d*x)-1). I want to get a, b, c, d values after fitting with custom equation.The problem I am facing is that, the curve fitting happens to be good in the initial part of the data points, then at the later points of data, it does not fit properly. How to tweak with fitoptions so that I can fit my data exactly with custom equation. Also, if there needs any change to be done in the script please help me with that too, so that I can fit it exactly. If you can provide me snaps of the script that you are following to fit kindly share that too as it will help me to understand properly.
I am attaching the data file for your reference.
Thank you
댓글 수: 14
채택된 답변
Cris LaPierre
2020년 10월 29일
fittype will allow you to define a custom equation to fit to your data, and fit will try to fit that equation to your data. Just a caution, your model is much more complex than your data requires. This means you will need to provide reasonable estimates for your initial guesses (StartPoint) for coefficients a-d.
data=readtable("675_base.xlsx");
ft = fittype('a*(1-exp(-b*x))+c*(exp(d*x)-1)',...
'dependent',{'y'},'independent',{'x'},...
'coefficients',{'a','b','c','d'});
f = fit(data.x,data.y,ft,'StartPoint',[0,0,0,0.25])
plot(f,data.x,data.y)
댓글 수: 5
VIGNESH BALAJI
2023년 7월 14일
@Cris LaPierre What method does fit use internally to fit equation with a data ?
Cris LaPierre
2023년 7월 14일
You could use the following syntax to determine what algorithm has been used to fit the data (output.algorithm).
You can then search how that algorithm performs fitting. In the example above, it is using the trust-region-reflective algorithm. You can use the fitOptions function to set desired algorithm options.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!