Continuous Probability Example

pdf

define the pieces of a probability density function and the x-values where f changes definition

Clear[f,f1,f2,f3,x1,x2]
f1[x_] := 0 
f2[x_]:= -3/8 (3-4 x+(x^2))
f3[x_] := 1/2(E^3) (E^(-x)) 
x1=1;
x2=3;

f[x_] := f1[x] /; (x<x1)
f[x_]:= f2[x]/; (x1≤ x<x2)
f[x_] :=f3[x]/; (x2≤ x)

Plot[f[x],{x,-3,10}]

This is more complicated but more like the graph we would show.  Dash the part on the axis is to make it show up better, and do not show the nonexistent vertical portion.

Clear[xmin,xmax];
xmin=-1; xmax=8;Show[{Plot[f[x],{x,xmin,x1-.01}, PlotStyle->{Red,Thickness[0.01],Dashing[{.05,.05}]}],
Plot[f[x],{x,x1+.01,x2-.01}, PlotStyle->{Red,Thickness[0.01]}],
Plot[f[x],{x,x2+.01,xmax}, PlotStyle->{Red,Thickness[0.01]}] },
PlotRange->{{xmin,xmax},{-0.001,.6}},AxesLabel->{" x ", "f[x] "}, PlotLabel->"Probability Density Function"]

(∫_xmin^x1)f1[t]\[DifferentialD]t+(∫_x1^x2)f2[t]\[DifferentialD]t+(∫_x2^xmax)f3[t]\[DifferentialD]t

N[%]

(∫_(-∞)^x1)f1[t]\[DifferentialD]t+(∫_x1^x2)f2[t]\[DifferentialD]t+(∫_x2^∞)f3[t]\[DifferentialD]t

cdf

The cdf is F[x_]:=(∫_(-∞)^x)f[t]dt, which depends upon where x is.

Certainly the area under the pdf to the left of x1 is zero.  
Suppose x is between 1 and 3

(∫_(-∞)^1)0\[DifferentialD]t+(∫_1^x) -3/8 (3-4 t+(t^2))\[DifferentialD]t

Suppose x is larger than 3

(∫_(-∞)^1)0\[DifferentialD]t+(∫_1^3) -3/8 (3-4 t+(t^2))\[DifferentialD]t+(∫_3^x) 1/2(E^3) (E^(-t))\[DifferentialD]t

Simplify[%]

Clear[F];
F[x_] := 0/;(x<x1)
F[x_] :=( (1/2)-((9 x)/8)+((3 (x^2))/4)-((x^3)/8))/;(x1≤ x<x2)
F[x_] := (1-((E^(3-x))/2))/;(x≥ x2)

Plot[F[x],{x,xmin,xmax}]

Plot[F[x],{x,xmin,xmax}, PlotStyle->{Red,Thickness[0.01]}]

relate cdf to pdf

Clear[xValue,cumValue];
xValue=1.3;
cumValue = F[xValue]

Show[{Plot[f1[x],{x,xmin,x1-.01}, PlotStyle->{Red,Thickness[0.01],Dashing[{.05,.05}]}],
Plot[f2[x],{x,x1+.01,x2-.01}, PlotStyle->{Red,Thickness[0.01]}],
Plot[f3[x],{x,x2+.01,xmax}, PlotStyle->{Red,Thickness[0.01]}] ,
Plot[f2[x],{x,x1,xValue}, 
PlotStyle->{Red,Thickness[0.01]},Filling->Axis,FillingStyle->Orange]},
PlotRange->{{xmin,xmax},{0,.5}},AxesLabel->{" x ", "f[x] "}, PlotLabel->"Probability Density Function"]

Show[{Plot[F[x],{x,xmin,xmax}, PlotStyle->{Red,Thickness[0.01]}],
Plot[F[xValue],{x,-1,3},PlotStyle->{Orange,Thickness[0.01]}] },AxesLabel->{" x ", "F[x] "}, PlotLabel->"Cumulative Distribution Function"]

Clear[delX]; delX = (x2-x1)/11.;Manipulate[Show[{Plot[f1[x],{x,xmin,x1-.01}, PlotStyle->{Red,Thickness[0.01],Dashing[{.05,.05}]}],
Plot[f2[x],{x,x1+.01,x2-.01}, PlotStyle->{Red,Thickness[0.01]}],
Plot[f3[x],{x,x2+.01,xmax}, PlotStyle->{Red,Thickness[0.01]}] ,
Plot[f2[x],{x,x1,LeftX}, 
PlotStyle->{Red,Thickness[0.01]},Filling->Axis,FillingStyle->Orange]},
PlotRange->{{xmin,xmax},{0,.5}},AxesLabel->{" x ", "f[x] "}, PlotLabel->"Probability Density Function"],{LeftX,x1+0.01,x2-.01,delX}]

Manipulate[Show[{Plot[F[x],{x,xmin,xmax}, PlotStyle->{Red,Thickness[0.01]}],
Plot[F[LeftX],{x,xmin,xmax},PlotStyle->{Orange,Thickness[0.01]}] },AxesLabel->{" x ", "F[x] "}, PlotLabel->"Cumulative Distribution Function"],{LeftX,x1+0.01,x2-.01,delX}]

Manipulate[
GraphicsGrid[{{Show[{Plot[f1[x],{x,xmin,x1-.01}, PlotStyle->{Red,Thickness[0.01],Dashing[{.05,.05}]}],
Plot[f2[x],{x,x1+.01,x2-.01}, PlotStyle->{Red,Thickness[0.01]}],
Plot[f3[x],{x,x2+.01,xmax}, PlotStyle->{Red,Thickness[0.01]}] ,
Plot[f2[x],{x,x1,LeftX}, 
PlotStyle->{Red,Thickness[0.01]},Filling->0,FillingStyle->Orange]},
PlotRange->{{xmin,xmax},{0,.5}},AxesLabel->{" x ", "f[x] "}, PlotLabel->"Probability Density Function"],
Show[{Plot[F[x],{x,xmin,xmax}, PlotStyle->{Red,Thickness[0.01]}],
Plot[F[LeftX],{x,xmin,xmax},PlotStyle->{Orange,Thickness[0.01]}] },AxesLabel->{" x ", "F[x] "}, PlotLabel->"Cumulative Distribution Function"]}}],{LeftX,x1+0.01,x2-.01,delX}]

Clear[delX];
delX = (xmax-x2)/10.;
Manipulate[
GraphicsGrid[{{Show[{Plot[f1[x],{x,xmin,x1-.01}, PlotStyle->{Red,Thickness[0.01],Dashing[{.05,.05}]}],
Plot[f2[x],{x,x1+.01,x2-.01}, PlotStyle->{Red,Thickness[0.01]},Filling->Axis,FillingStyle->Orange],
Plot[f3[x],{x,x2+.01,xmax}, PlotStyle->{Red,Thickness[0.01]}] ,
Plot[f3[x],{x,x2,LeftX}, 
PlotStyle->{Red,Thickness[0.01]},Filling->0,FillingStyle->Orange]},
PlotRange->{{xmin,xmax},{0,.5}},AxesLabel->{" x ", "f[x] "}, PlotLabel->"Probability Density Function"],
Show[{Plot[F[x],{x,xmin,xmax}, PlotStyle->{Red,Thickness[0.01]}],
Plot[F[LeftX],{x,xmin,xmax},PlotStyle->{Orange,Thickness[0.01]}] },AxesLabel->{" x ", "F[x] "}, PlotLabel->"Cumulative Distribution Function"]}}],{LeftX,x2+0.01,xmax-.01,delX}]