MATLAB Examples

## EXAMPLES for TDIST function

```%TDIST Computes the distribution (PDF, CDF or QF - quantiles) % of a linear combination of independent SYMMETRIC % (zero-mean) random variables (RVs) with specific % distributions: % - STUDENT's t distribution with 0 < df < Inf, % - NORMAL distribution N(0,1), % - RECTANGULAR (uniform) distribution R(-1,1), % - symmetric TRIANGULAR distribution T(-1,1), % - symmetric ARCSINE distribution (U-distribution) U(-1,1), % - symmetric CHI2 (mixture of CHI2 and -CHI2) distribution. % Viktor Witkovsky (witkovsky@gmail.com) % Ver.: 01-Dec-2014 01:30:48 ```

## EXAMPLE 1: (CDF of a linear combination of RVs defined by df)

```CDF of a linear combination of independent SYMMETRIC (zero-mean) random
variables (RVs) with Normal, Student's t_1, Rectangular, Triangular, and
U-shaped distribution.```
```df = [Inf 1 -1 -2 -3]; lambda = [1 1 5 1 10]; funtype = 1; [cdf,x,resultCDF] = tdist([],df,lambda,funtype); disp([x(200:end) cdf(200:end)]) disp(resultCDF) ```
``` 29.360142711437216 0.988296871607822 29.767922471318290 0.988483997422920 30.175702231199363 0.988664769424483 30.583481991080436 0.988839542228926 30.991261750961506 0.989008627388295 31.399041510842576 0.989172300862769 31.806821270723649 0.989330824121880 32.214601030604726 0.989484457014191 32.622380790485799 0.989633450608534 33.030160550366865 0.989778030916215 33.437940310247939 0.989918393813529 33.845720070129012 0.990054717794097 34.253499830010085 0.990187180794242 34.661279589891159 0.990315963301841 35.069059349772232 0.990441235993720 35.476839109653305 0.990563147415444 35.884618869534371 0.990681826381983 36.292398629415445 0.990797396580408 36.700178389296518 0.990909987231118 37.107958149177591 0.991019728690162 37.515737909058664 0.991126739143499 37.923517668939738 0.991231118224517 38.331297428820811 0.991332954948114 38.739077188701884 0.991432340967832 39.146856948582958 0.991529374496440 39.554636708464031 0.991624151224992 39.962416468345104 0.991716753275633 40.370196228226170 0.991807249002468 40.777975988107244 0.991895703784799 41.185755747988317 0.991982189575425 41.593535507869390 0.992066782767050 42.001315267750464 0.992149553410818 42.409095027631537 0.992230558429478 42.816874787512603 0.992309846541461 43.224654547393676 0.992387469167103 43.632434307274750 0.992463485022094 44.040214067155823 0.992537953585297 44.447993827036896 0.992610925297874 44.855773586917969 0.992682439784360 45.263553346799043 0.992752533997158 45.671333106680116 0.992821250933556 46.079112866561189 0.992888639192537 46.486892626442263 0.992954744242305 46.894672386323336 0.993019601589931 47.302452146204409 0.993083239607481 47.710231906085475 0.993145688649976 48.118011665966549 0.993206986082598 48.525791425847622 0.993267171726701 48.933571185728688 0.993326279196542 49.341350945609761 0.993384333094258 49.749130705490835 0.993441355150338 50.156910465371908 0.993497372203893 50.564690225252981 0.993552417011526 50.972469985134055 0.993606521202025 51.380249745015128 0.993659708590305 51.788029504896201 0.993711996456646 options: [1x1 struct] fun: [255x1 double] x: [255x1 double] chebfun: [] xmax: 51.788029504896201 df: [5x1 double] lambda: [5x1 double] N: 128 n: 128 minprob: 1.000000000000000e-03 var: 74.500000000000000 norml: 11.313708498984761 xlow: -51.788029504896201 xupp: 51.788029504896201 Tmax: 31.415926535897931 Tmax2: 31.059212988320052 dt: 0.245436926061703 dt2: 0.060662525367813 limits: [5x1 double] subInts: [4x1 double] t: [1904x1 double] weights: [1904x1 double] weightChf: [1904x1 double] ```

## EXAMPLE 2: (PDF of a linear combination of RVs defined by df)

```PDF of a linear combination of independent SYMMETRIC (zero-mean) random
variables (RVs) with Normal, Student's t_1, Rectangular, Triangular, and
U-shaped distribution.```
```options = []; options.isChebfun = true; options.isPlot = false; options.N = 2^8; options.n = 2^8; df = [Inf 1 -1 -2 -3]; lambda = [1 1 5 1 10]; funtype = 2; [~,~,resultPDF] = tdist([],df,lambda,funtype,options); % CHEBFUN representation of the PDF % Non-adaptive procedure defined by (given) pre-selected Chebyshev points PDF = resultPDF.chebfun; plot(PDF) ```

## EXAMPLE 3: (Quantiles of a linear combination of RVs defined by df)

```QF of a linear combination of independent SYMMETRIC (zero-mean) random
variables (RVs) with Normal, Student's t_1, Rectangular, Triangular, and
U-shaped distribution.```
```options = []; options.isPlot = false; df = [Inf 1 -1 -2 -3]; lambda = [1 1 5 1 10]; funtype = 3; prob = [0.9 0.95 0.99]'; qf = tdist(prob,df,lambda,funtype,options); disp([prob qf]); ```
``` 0.900000000000000 11.424001320036231 0.950000000000000 13.938405426241488 0.990000000000000 33.680623448250699 ```

## EXAMPLE 4: (Characterictic function of a linear combination of RVs)

```CHF of a linear combination of independent SYMMETRIC (zero-mean) random
variables (RVs) with Normal, Student's t_1, Rectangular, Triangular, and
U-shaped distribution.```
```options = []; options.isChebfun = true; options.isPlot = false; options.N = 2^10; options.n = 2^10; df = [Inf 1 -1 -2 -3]; lambda = [1 1 5 1 10]; funtype = 4; [chf,~,resultCHF] = tdist([],df,lambda,funtype,options); % CHEBFUN representation of the CHF % Non-adaptive procedure defined by (given) pre-selected Chebyshev points CHF = resultCHF.chebfun; plot(CHF) ```

## EXAMPLE 5 (Create PDF as a CHEBFUN function and use it to compute CDF)

```PDF of a linear combination of independent SYMMETRIC (zero-mean) random
variables (RVs) with symmetric CHI2 (mixture of CHI2 and -CHI2)
distribution.```
```df_true = [1 2 3 10]; df = -10 - df_true; % symmetric chi2-mixture distributions lambda = [1 1 1 1]; funtype = 2; N = 2^10; xmax = 130; x = -xmax * cos((0:N)*pi/N); pdf = tdist(x,df,lambda,funtype); PDF = chebfun(pdf,[-xmax,xmax]); integrate = sum(PDF); cdf = cumsum(PDF); xnew = linspace(-50,50); figure plot(xnew,cdf(xnew)) ```

## EXAMPLE 6: (Create Quantile function QF as a CHEBFUN function)

```QF of a linear combination of independent SYMMETRIC (zero-mean) random
variables (RVs) with Normal, Student's t_1, Rectangular, Triangular, and
U-shaped distribution.```
```options = []; options.isChebfun = true; options.n = 2^8; options.N = 2^8; df = [Inf 1 -1 -2 -3]; lambda = [1 1 5 1 10]; funtype = 3; [qf,prob,resultsQF] = tdist([],df,lambda,funtype,options); % Use CHEBFUN QF for computing (interpolating) arbitrary quantiles QF = resultsQF.chebfun; disp(QF([0.9 0.95 0.99]')) ```
``` 11.424004611125653 13.938412056892716 33.680637219065432 ```

## EXAMPLE 7: (Create Quantile function QF as a CHEBFUN function)

```Distribution of a linear combination of independent SYMMETRIC
(zero-mean) random  variables (RVs) with Normal, Student's t_1, and
Rectangular distribution.```
```options = []; options.isChebfun = true; options.isPlot = false; options.n = 2^8; options.N = 2^8; df = [Inf 1 3 5 10 -1]; lambda = [1 0.5 1 2 3 20]; funtype = 2; [pdf,x,results] = tdist([],df,lambda,funtype,options); % Use CHEBFUN PDF for computing (interpolating) arbitrary quantiles PDF = results.chebfun; plot(PDF) ```