MATLAB Examples

## Generate N Standard Normally Distributed Random Variable

```N = 1000000; X = randn(N,1); ```

## Points for which CDF and PDF are to be evaluated

```x = linspace(-10,10,1000); ```

## Estimate PDF and CDF

```[f,F] = EstimateDistribution(X,x); ```

## Plot Results

```figure(1); plot(x,f,x,F); xlabel('x'); ylabel('Simulated PDF & CDF'); str1 = strcat('PDF;','Area = ',num2str(trapz(x,f))); legend(str1,'CDF','Location','northwest'); ```

## Standard Deviation

```N = 1000000; mu = -1; sigma = 5; X = mu + sigma*randn(N,1); ```

## Points for which CDF and PDF are to be evaluated

```x = linspace(-10,10,1000); ```

## Theoretical PDF and CDF

```fx = (1/sqrt((2*pi*sigma*sigma)))*exp(-(((x - mu).^2)/(2*sigma*sigma))); Fx = 0.5*(1 + erf((x - mu)/(sqrt(2*sigma*sigma)))); ```

## Estimate PDF and CDF

```[f,F] = EstimateDistribution(X,x); ```

## Plot Results

```figure(2); plot(x,f,x,fx,x,F,x,Fx); xlabel('x'); ylabel('PDF & CDF'); str1 = strcat('Simulated PDF;','Area = ',num2str(trapz(x,f))); str2 = strcat('Theoretical PDF;','Area = ',num2str(trapz(x,fx))); legend(str1,str2,'Simulated CDF','Theoretical CDF','Location','northwest'); ```

## Generate N Uniformaly Distributed Random Variable

```N = 1000000; X = rand(N,1); ```

## Points for which CDF and PDF are to be evaluated

```x = linspace(-10,10,1000); ```

## Estimate PDF and CDF

```[f,F] = EstimateDistribution(X,x); ```

## Plot Results

```figure(3); plot(x,f,x,F); xlabel('x'); ylabel('Simulated PDF & CDF'); str1 = strcat('PDF;','Area = ',num2str(trapz(x,f))); legend(str1,'CDF','Location','northwest'); ```