Skip to content

Instantly share code, notes, and snippets.

@StanczakDominik
Created June 13, 2018 16:03
Show Gist options
  • Save StanczakDominik/31471ac2afdd7603f7d89663c5db7e49 to your computer and use it in GitHub Desktop.
Save StanczakDominik/31471ac2afdd7603f7d89663c5db7e49 to your computer and use it in GitHub Desktop.
Probability density
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"N = int(1e8)\n",
"phi = np.random.random(N) * np.pi\n",
"x = np.cos(phi)\n",
"modx = np.abs(x)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYMAAAEKCAYAAADw2zkCAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAF8JJREFUeJzt3XuQXFed2PHvbzR6WJb81NjGD1Y22MQuNhuDWGAJr7XZ8kLAqVo2ZVLewIbEVaTCEkIlgVCJU2yqEorN1sIWtax3cXgEWMCQYDAJxsbYi3ftWDaO8RPLT71sjSVLljQjzUz3L3/cljQadWt6pOl7u/t+P1Vdffvc2/f87ox0fnPOuY/ITCRJ9TZSdQCSpOqZDCRJJgNJkslAkoTJQJKEyUCShMlAkoTJQJKEyUCSBIxWHUC31qxZk2vXrq06DEkaKPfee+8LmTk233YDkwzWrl3L+vXrqw5DkgZKRDzTzXYOE0mSTAaSJJOBJAmTgSQJk4EkiQE6m0iSamFqArY9DAQEECPFa/QEGLuoZ9WaDCSpn+wdhzs+c2T5yefBu/6oZ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ZDcwWyVIFrgU9FxBnApcBAXtktgVcgS8clIm6nuN3H2zJzd9XxSMfKYSLpGEXErwIvA6ZMBBp0JgPpGLSeMPU1iqdP7RmCB8qo5kwG0gJFxErgu8DHMvMRisdsXlttVNLxcc5AkmTPQJJkMpAkYTKQJGEykCRhMpAkYTKQJGEykCRhMpAkAf8f4elBfD0MSNAAAAAASUVORK5CYII=\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"(values, edges, patches) = plt.hist(modx, bins=50, density=True)\n",
"x_plot = np.linspace(0, 1, 600, endpoint=False)\n",
"plt.plot(x_plot, 2/(np.pi * np.sqrt(1-x_plot**2)), lw=6, alpha=0.7)\n",
"plt.xlabel(\"$x$\")\n",
"plt.ylabel(r\"f_|x|(x)\")\n",
"plt.savefig('rozklad.png', transparent=False)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment