Creating a custom PDF to find the parameters

3 views (last 30 days)
Hello,
I have 4 known discharge values as well as their probabilities. I am trying to write my own matlab code to give me the 3 parameters associated with these known values. The log-pearson type 3 distribution isn't built into matlab, so this requires me to write a custom pdf function for it. This is where I am getting my errors. I have tried:
custpdf=@(Q,a) (1/(Q*abs(a(1))*gamma(a(2))))*((ln(Q)-a(3))/a... )^(a(2)-1)*exp(-(ln(Q)-a(3))/a(1));
as well as:
custpdf=@(Q,a,b,c) (1/(Q*abs(a)*gamma(b)))*((ln(Q)-c)/a... )^(b-1)*exp(-(ln(Q)-c)/a);
I am getting a not enough input arguments for both cases. Next the code I am trying to use is to estimate the parameters via minimizing the R^2 value:
Flogp3pdf = @(a,b,c) sum((Po - custpdf(Q,a,b,c)).^2);
Where Po are my known probabilities associated with my known discharge values, Q.
[a,b,c] = fminsearch(Flogp3pdf,[1,1,1]);
[a,b,c,fval]=fminsearch(custpdf,[1,1,1]);
I figured this would work because a friend had a similar code to estimate the parameters for the lognormal distribution. I got that code and modified it to work for the Log-pearson3. However, it's not that simple and I am having trouble.
some errors I am getting are:
Error in fminsearch (line 190) fv(:,1) = funfcn(x,varargin{:});
Error in pearson_fit (line 17) [a,b,c,fval]=fminsearch(custpdf,[1,1,1]);
Any help whatsoever would be welcome. I am a somewhat novice coder and I have tried reading through the MLE as well as fminsearch help pages and I can't seem to figure this out.
Thank you in advance!!
PS: the code that I am trying to model it after is only 2 lines:
% begin - fit lognormal parameters by minimizing the sum of squares error
Flogcdf = @(c) sum((Pf - logncdf(Sa,c(1),c(2))).^2); [c] = fminsearch(Flogcdf,[1,1]);
% end - fit lognormal parameters by minimizing the sum of squares error
-David

Answers (0)

Categories

Find more on Oceanography and Hydrology in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!