From: Hua He on 25 Apr 2010 04:30 Hello, Just for example: I have points with x = [1;2;3;4;5]; y = [0.05;0.1;0.25;0.55;0.95]; I want to use cumulative density function (cdf) of log normal distrbution to fit these five points (simply put, I just want to use the cdf of lognormal to fit five points, not meaning that these five points are lognormal distributed). For this, I did the following: BETA0 = [5; 0.1]; BETA = NLINFIT(x,y,'logncdf',BETA0); However, I got the following error messaage: ??? Error using ==> nlinfit at 120 Error evaluating model function 'logncdf'. Caused by: Error using ==> logncdf at 65 Non-scalar arguments must match in size. Could you please advise me where I am doing wrong? Thanks a lot!!! Dan
From: John D'Errico on 25 Apr 2010 05:51 "Hua He" <ttuwind(a)yahoo.com> wrote in message <hr0uiu$1c4$1(a)fred.mathworks.com>... > Hello, > > Just for example: I have points with x = [1;2;3;4;5]; y = [0.05;0.1;0.25;0.55;0.95]; > > I want to use cumulative density function (cdf) of log normal distrbution to fit these five points (simply put, I just want to use the cdf of lognormal to fit five points, not meaning that these five points are lognormal distributed). For this, I did the following: > BETA0 = [5; 0.1]; > BETA = NLINFIT(x,y,'logncdf',BETA0); > > However, I got the following error messaage: > ??? Error using ==> nlinfit at 120 > Error evaluating model function 'logncdf'. > Caused by: > Error using ==> logncdf at 65 > Non-scalar arguments must match in size. > > Could you please advise me where I am doing wrong? Thanks a lot!!! > Dan The problem is logncdf takes THREE arguments. >> help logncdf LOGNCDF Lognormal cumulative distribution function (cdf). P = LOGNCDF(X,MU,SIGMA) returns ... So you wish to pass in MU and SIGMA, inside the parameters beta. At least, that is what you think you are doing. The computer is very stupid though. You tell it what to do, and it follows your instructions EXACTLY. So when nlinfit calls logncdf, it passes in both elements of beta into the argument mu. Lets try it, and see what happens. x = 1:5; logncdf(x,[1 2]) ??? Error using ==> logncdf at 65 Non-scalar arguments must match in size. The function logncdf has no idea that I passed it both mu and sigma in one argument. (To be honest, I think the author should have checked for this case. I.e., if only two arguments are passed in, and the SECOND argument is a vector of size two, then don't throw an error. This is how you write friendly code. On the other hand it sometimes also slows down your code slightly, by having extra checks for all possible dumb operator errors if your code is excessively friendly.) Regardless, you need to know how to call logncdf. MATLAB will not read the help for you, and know what to do. The point of all this is you need to split the parameters up, and pass the arguments all properly into logncdf. This might work better: BETA0 = [5; 0.1]; BETA = nlinfit(x,y,@(B,x) logncdf(x,B(1),B(2)),BETA0); Warning: Rank deficient, rank = 1, tol = 4.9396e-263. > In nlinfit>LMfit at 294 In nlinfit at 166 Warning: Rank deficient, rank = 0, tol = 0.0000e+00. > In nlinfit>LMfit at 294 In nlinfit at 166 Warning: The Jacobian at the solution is ill-conditioned, and some model parameters may not be estimated well (they are not identifiable). Use caution in making predictions. > In nlinfit at 223 BETA = 5 2.98932696329767e+247 Ok, so we get garbage out. The answer is to plot your data. plot(x,y) Were you to do so, you would see that this simply does not look like any lognormal distribution CDF known to mankind (or computerkind, for that matter.) So the moral is, first, to plot your data. Don't just throw it at nlinfit without looking, or expect garbage out. Second, remember that computers are stupid beasts. Don't expect them to think for you. John
|
Pages: 1 Prev: gmsk filter in receiver Next: detection of tuberoclosis bacili using digital image processing |