how to plot exponential pdf over a distributed data ?
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Amr Hashem
il 24 Ott 2015
Commentato: Star Strider
il 26 Ott 2015
in order to find the best fit model
I want to produce this figure (a data & best fit over it):
so I try:
v=1:25;
n=[10;7;6;21;14;18;23;33;28;31;34;30;32;48;43;46;39;47;40;45;51;47;45;45;23];
plot(v,n,'*b')
ex=expfit(n);
E=exppdf(n,ex);
hold on
plot(v,E,'-r')
but it produce this figure:
how to modify the code to get the first figure?
Risposta accettata
Star Strider
il 24 Ott 2015
Fourteen hours ago I was asleep here in GMT-7 land.
I believe you are mistaking the exponential distribution for the exponential function.
This produces a good fit to your data:
v=1:25;
n=[10;7;6;21;14;18;23;33;28;31;34;30;32;48;43;46;39;47;40;45;51;47;45;45;23];
plot(v,n,'bp')
expfcn = @(b,x) b(1) + b(2).*exp(b(3).*x); % Three-Parameter Exponential Function
B0 = [50; -50; -0.5]; % Initial Parameter Estimates
B = nlinfit(v(:), n(:), expfcn, B0); % Estimate Parameters
E = expfcn(B,v); % Simulate Function
hold on
plot(v,E,'-r')
I used the nlinfit function because I know you have the Statistics Toolbox.
6 Commenti
Star Strider
il 26 Ott 2015
The x-intercept, such as it is, fzero calculates as -20970.520.
You could probably find the intercept manually, but your code is incorrect when estimating the parameters.
My code here is the correct method:
v=1:25;
n=[10;7;6;21;14;18;23;33;28;31;34;30;32;48;43;46;39;47;40;45;51;47;45;45;23];
plot(v,n,'*b')
expfcn = @(b,x) b(1).*exp(b(2).*x); % Two-Parameter Exponential Function
B0 = [50; 0]; % Initial Parameter Estimates
B = nlinfit(v(:), n(:), expfcn, B0); % Estimate Parameters
Y0 = fzero(@(x)expfcn(B,x), 1); % Find ‘v’ At E=0
vrng = linspace(Y0, max(v)); % Create Matching Vector
E = expfcn(B,vrng); % Simulate Function
hold on
plot(vrng,E,'-r')
fprintf(1, '\n\tE(%.3f) = 0\n', Y0)
You are only fitting two parameters, so you can only specify two in the nlinfit argument list, and you have to refer to them correctly in the ‘expfcn’ objective function. Otherwise, nlinfit will attempt to fit all three of them, even though your function is using only two, and will likely return inaccurate results for the two it does estimate.
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!