#!/usr/bin/env python # coding: utf-8 # CDF: # $$ # F(x) = \begin{cases} # 0 & x <0,\\ # x & 0 \leq x < 0.5,\\ # \frac{x}{2} + 0.5 & 0.5 \leq x \leq 1\\ # 1 & x>2 # \end{cases} # $$ # # P*D*F: # # $$ # f(x) = \begin{cases} # 0 & x <0,\\ # 1 & 0 \leq x < 0.5,\\ # \frac{1}{2} & 0.5 \leq x \leq 1\\ # 0 & x>2 # \end{cases} # $$ # # $\int f(t) dt = 0.75$?? # # What's missing? # # p[X=0.5] = 0.25. But defining such a probability should be $0$ for a P*D*F.[It's technically a 'PMF'. The mass at 0.5 being 1/4] # In[15]: get_ipython().run_line_magic('matplotlib', 'inline') from __future__ import division def F(x): if x<0: return 0 if x<0.5: return x if x>=0.5 and x<=1: return x/2+0.5 return 1 import numpy as np import matplotlib.pyplot as plt x = np.linspace(-2,2, num=100) fx =[F(i) for i in x] pos = np.where((x<=0.51) & (x>=0.49))[0] x[pos] = np.nan fx[pos] = np.nan plt.plot(x,fx)