fitting a dual exponential function using nlinfit
Mostra commenti meno recenti
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 Commenti
the cyclist
il 13 Gen 2020
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
il 13 Gen 2020
the cyclist
il 14 Gen 2020
Modificato: the cyclist
il 14 Gen 2020
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,'-')
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Linear and Nonlinear Regression in Centro assistenza e File Exchange
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)

