fitting a dual exponential function using nlinfit
이전 댓글 표시
I am trying to use nlinfit to find the function that best fits the following set of points:

According to some litterature review this curve could be best described by a dual exponential model defined as:

where a, b, c, d an h are parameters that need to be calibrated using nlinfit.
However, when I use nlinfit my calibration goes terrible and I when I plot the approximation I get something like this:

when what I want is to get something like this:

Is there a way to know which could be the ideal initial conditions?
This is the code that I use to fit the function:
where y axis=Price and x axis=x
%Defining the function to fit
f = @(c,x) (c(5)+(exp((x-c(1))./c(2))-exp(-(x-c(3))./c(4)))./2);
%Setting a guess to start the fit
a=max(x)/10;
initials=[a a a a a];
%Making the curve fit
new_coeffs=nlinfit(x,Price,f,initials)
%Evaluate the new coefficients into the function
new_y=f(new_coeffs,x);
%Plot the approximation
figure(2)
plot(x,Price,...
x,new_y)
Any suggestion of how to get me closer to what I want are really welcome!
Thanks in advance!
댓글 수: 3
the cyclist
2020년 1월 13일
It would be helpful if you uploaded your data and code. Otherwise, it's not possible to see if you just made some simple coding error.
Also, how are you plotting the fit? I assume the lines going back and forth are due to the fact that your x values are not monotonically increasing. You might want to change that, to see what the fit curve really looks like. (But it certainly looks poor, regardless.)
You might also try simply plotting that function for S(t) with arbitrary parameters, and not superimposed on the data, to get a feel for how it behaves. This might also allow you to choose starting values better.
Angelavtc
2020년 1월 13일
the cyclist
2020년 1월 14일
편집: the cyclist
2020년 1월 14일
Uploading the data as well would be helpful.
Please take my advice about plotting S(t) for different parameters, and using that to guide your initial guess at parameters (your variable initials). Those guesses are probably terrible. Are you getting convergence warnings from nlinfit?
To plot the fit, don't use the original data. Just create values of x that are uniformly spaced. For example
new_x = 1.e4 * (1:0.05:4);
new_y=f(new_coeffs,x);
and then plot the data as points, and the fit as a line:
plot(x,Price,'o',...
x,new_y,'-')
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 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!

%203.53.30%20p.%20m..png)

