How do define a lognormal pdf function handle inline?

Lognormal is just an example, I know that lognormpdf built-in function is existed in MATLAB. But suppose we want to define it. We can write: lognormal = @(p,x) exp(-(log(x)-p(1)).^2./p(2).^2/2)./x/p(2)/sqrt(2*pi); The problem is, that lognormal([1,1],0) is NaN. Is it possible to modify the definition easily to restrict lognormal([anything],0) = 0?

답변 (1개)

Star Strider
Star Strider 2016년 12월 4일

0 개 추천

For the lognormal distribution functions, I usually replace the zero values with sqrt(eps) or realmin, whatever seems most appropriate at the time. You can use the isnan function to detect the NaN values and replace them with the value you choose as appropriate, depending of course on the function you are using.

카테고리

도움말 센터File Exchange에서 Function Creation에 대해 자세히 알아보기

질문:

2016년 12월 4일

답변:

2016년 12월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by