octave-maintainers
[Top][All Lists]

## Re: Package statistics: tricdf (bug?)

 From: Dmitri A. Sergatskov Subject: Re: Package statistics: tricdf (bug?) Date: Wed, 24 Jun 2020 18:39:02 -0400

On Tue, Jun 23, 2020 at 5:37 AM Evangelos Rozos <erozos@gmail.com> wrote:
I think something is wrong with tricdf function (maybe triinv also).

>> tricdf (0.7, 0.5, 1.0, 0.9)

ans =  0.16000

The correct answer should be 0.2.

MATLAB gives 0.2. This value can be also verified by the geometry of the
pdf triangle with base from 0.5 to 1, and height 4 at 0.9. Then, the
area of the triangle with base from 0.5 to 0.7 and height 2 (0.7 is in
the middle of the 0.5 to 0.9 segment) is 0.2.

tricdf code has few problems.  For you reported problem this fix should work:
<     area = (x(k_temp) - a).^2 * h;
---
>     area = (x(k_temp) - a).^2 * h / (c - a) / 2 ;
74c74
<     area = (b-x(k_temp)).^2 * h;
---
>     area = (b-x(k_temp)).^2 * h / (b - c) / 2 ;

A similar change should be done for the code segment that deals with the case of
A,B, and C being arrays rather than scalar. I really do not understand the intent of that code.
It requires the size of X, A, B, and C to be the same. That does not make much sense to me.
I think A, B and C should be scalars. I do not think there is a compatible matlab's function.

Dmitri.
--