diff --git a/14_stats_and_montecarlo/.ipynb_checkpoints/16_stats_and_montecarlo-checkpoint.ipynb b/14_stats_and_montecarlo/.ipynb_checkpoints/16_stats_and_montecarlo-checkpoint.ipynb
new file mode 100644
index 0000000..5482e1b
--- /dev/null
+++ b/14_stats_and_montecarlo/.ipynb_checkpoints/16_stats_and_montecarlo-checkpoint.ipynb
@@ -0,0 +1,20583 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "collapsed": true,
+ "slideshow": {
+ "slide_type": "skip"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "setdefaults"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": true,
+ "slideshow": {
+ "slide_type": "skip"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "%plot --format svg"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "# Statistics and Monte-Carlo Models\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "## Statistics\n",
+ "\n",
+ "How do we describe *precision* and *accuracy*?\n",
+ "\n",
+ "- mean\n",
+ "\n",
+ "- standard deviation\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "## Monte Carlo Simulations\n",
+ "\n",
+ "Monte Carlo models use random numbers to either understand statistics or generate a solution. \n",
+ "\n",
+ "### Example 1:\n",
+ "#### Calculate $\\pi$ with random numbers. \n",
+ "\n",
+ "Assuming we can actually generate random numbers (a topic of philosophical and heated debates) we can populate a unit square with random points and determine the ratio of points inside and outside of a circle.\n",
+ "\n",
+ "\n",
+ "\n",
+ ""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "The ratio of the area of the circle to the square is:\n",
+ "\n",
+ "$\\frac{\\pi r^{2}}{4r^{2}}=\\frac{\\pi}{4}$\n",
+ "\n",
+ "So if we know the fraction of random points that are within the unit circle, then we can calculate $\\pi$\n",
+ "\n",
+ "(number of points in circle)/(total number of points)=$\\pi/4$"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "fragment"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "function our_pi=montecarlopi(N)\n",
+ " % Create random x-y-coordinates\n",
+ "\n",
+ " x=rand(N,1);\n",
+ " y=rand(N,1);\n",
+ " R=sqrt(x.^2+y.^2); % compute radius\n",
+ " num_in_circle=sum(R<1);\n",
+ " total_num_pts =length(R);\n",
+ " our_pi = 4*num_in_circle/total_num_pts;\n",
+ "end\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "mean value for pi = 3.141720\n",
+ "standard deviation is 0.000502\n",
+ "actual pi is 3.141593\n"
+ ]
+ }
+ ],
+ "source": [
+ "test_pi=zeros(10,1);\n",
+ "for i=1:10\n",
+ " test_pi(i)=montecarlopi(10000000);\n",
+ "end\n",
+ "fprintf('mean value for pi = %f\\n',mean(test_pi))\n",
+ "fprintf('standard deviation is %f',std(test_pi))\n",
+ "fprintf('actual pi is %f',pi)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "### Example 2\n",
+ "#### Determine uncertainty in failure stress based on geometry\n",
+ "\n",
+ "In this example, we know that a steel bar will break under 940 MPa tensile stress. The bar is 1 mm by 2 mm with a tolerance of 1 %. What is the range of tensile loads that can be safely applied to the beam?\n",
+ "\n",
+ "$\\sigma_{UTS}=\\frac{F_{fail}}{wh}$\n",
+ "\n",
+ "$F_{fail}=\\sigma_{UTS}wh$"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "ans = 1.8803\n",
+ "ans = 0.021802\n"
+ ]
+ },
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "N=1000;\n",
+ "r=rand(N,1);\n",
+ "wmean=1; % in mm\n",
+ "wmin=wmean-wmean*0.01;\n",
+ "wmax=wmean+wmean*0.01;\n",
+ "hmean=2; % in mm\n",
+ "hmin=hmean-hmean*0.01;\n",
+ "hmax=hmean+hmean*0.01;\n",
+ "\n",
+ "wrand=wmin+(wmax-wmin)*r;\n",
+ "hrand=hmin+(hmax-hmin)*r;\n",
+ "\n",
+ "uts=940; % in N/mm^2=MPa\n",
+ "\n",
+ "Ffail=uts.*wrand.*hrand*1e-3; % force in kN\n",
+ "hist(Ffail,20,1)\n",
+ "xlabel('failure load (kN)')\n",
+ "ylabel('relative counts')\n",
+ "mean(Ffail)\n",
+ "std(Ffail)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "Normally, the tolerance is not a maximum/minimum specification, but instead a normal distribution that describes the standard deviation, or the 68 % confidence interval.\n",
+ "\n",
+ "So instead, we should generate normally distributed dimensions."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "ans = 1.8800\n",
+ "ans = 0.026571\n"
+ ]
+ },
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "N=100000;\n",
+ "wmean=1; % in mm\n",
+ "wstd=wmean*0.01; % standard deviation in mm\n",
+ "hmean=2; % in mm\n",
+ "hstd=hmean*0.01; % standard deviation in mm\n",
+ "\n",
+ "\n",
+ "wrand=normrnd(wmean,wstd,[N,1]);\n",
+ "hrand=normrnd(hmean,hstd,[N,1]);\n",
+ "uts=940; % in N/mm^2=MPa\n",
+ "\n",
+ "Ffail=uts.*wrand.*hrand*1e-3; % force in kN\n",
+ "hist(Ffail,20,1)\n",
+ "xlabel('failure load (kN)')\n",
+ "ylabel('relative counts')\n",
+ "mean(Ffail)\n",
+ "std(Ffail)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "# Thanks"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "# Using data from Dart board experiment"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 173,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "darts=dlmread('compiled_data.csv',',');\n",
+ "x_darts=darts(:,1).*cosd(darts(:,2));\n",
+ "y_darts=darts(:,1).*sind(darts(:,2));\n",
+ "\n",
+ "colormap(colorcube(length(darts(:,3))))\n",
+ "\n",
+ "scatter(x_darts, y_darts, [], darts(:,3))\n",
+ "xlabel('x position (cm)')\n",
+ "ylabel('y position (cm)')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 174,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "mu_x = 0.90447\r\n"
+ ]
+ }
+ ],
+ "source": [
+ "mu_x=mean(x_darts)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "s_x = 4.2747\r\n"
+ ]
+ }
+ ],
+ "source": [
+ "s_x=std(x_darts)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 175,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "mu_y = 0.88450\r\n"
+ ]
+ }
+ ],
+ "source": [
+ "mu_y=mean(y_darts)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 177,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "s_y = 4.6834\r\n"
+ ]
+ }
+ ],
+ "source": [
+ "s_y=std(y_darts)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 180,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "hist(x_darts,30,100)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 182,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "x_vals=linspace(-15,20,30);\n",
+ "hist(x_darts,x_vals,1);\n",
+ "[histFreq, histXout] = hist(x_darts, 30);\n",
+ "binWidth = histXout(2)-histXout(1);\n",
+ "bar(histXout, histFreq/binWidth/sum(histFreq));\n",
+ "pdfnorm = @(x) 1/sqrt(2*s_x^2*pi).*exp(-(x-mu_x).^2/2/s_x^2);\n",
+ "%cdfnorm = @(x) 1/2*(1+erf((x-mu_x)./sqrt(2*s_x^2)));\n",
+ "%hist(x_darts,x_vals,trapz(x,f))%,cdfnorm(max(x_darts))/2)\n",
+ "hold on;\n",
+ "plot(x_vals,pdfnorm(x_vals))\n",
+ "n=2; % n=1, 68% confidence, n=2, 95% confidence, n=3, 99% conf\n",
+ " plot([mu_x+n*s_x,mu_x+n*s_x],[0,0.1],'r-')\n",
+ " plot([mu_x-n*s_x,mu_x-n*s_x],[0,0.1],'r-')\n",
+ "\n",
+ "xlabel('x position (cm)')\n",
+ "ylabel('relative counts')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 183,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "y_vals=linspace(-15,20,30);\n",
+ "hist(y_darts,y_vals,1);\n",
+ "[histFreq, histXout] = hist(y_darts, 30);\n",
+ "binWidth = histXout(2)-histXout(1);\n",
+ "bar(histXout, histFreq/binWidth/sum(histFreq));\n",
+ "pdfnorm = @(x) 1/sqrt(2*s_y^2*pi).*exp(-(x-mu_y).^2/2/s_y^2);\n",
+ "%cdfnorm = @(x) 1/2*(1+erf((x-mu_x)./sqrt(2*s_x^2)));\n",
+ "%hist(x_darts,x_vals,trapz(x,f))%,cdfnorm(max(x_darts))/2)\n",
+ "hold on;\n",
+ "plot(y_vals,pdfnorm(y_vals))\n",
+ "n=2; % n=1, 68% confidence, n=2, 95% confidence, n=3, 99% conf\n",
+ " plot([mu_y+n*s_y,mu_y+n*s_y],[0,0.1],'r-')\n",
+ " plot([mu_y-n*s_y,mu_y-n*s_y],[0,0.1],'r-')\n",
+ "\n",
+ "xlabel('x position (cm)')\n",
+ "ylabel('relative counts')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 76,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "x_exp=empirical_cdf(x_vals,x_darts);\n",
+ "plot(x_vals,x_exp)\n",
+ "hold on;\n",
+ "plot(x_vals,normcdf(x_vals,mu_x,s_x),'k-')\n",
+ "legend('experimental CDF','Normal CDF','Location','SouthEast')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 185,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "% plot the distribution in x- and y-directions\n",
+ "gauss2d = @(x,y) exp(-((x-mu_x).^2/2/s_x^2+(y-mu_y).^2/2/s_y^2));\n",
+ "\n",
+ "x=linspace(-20,20,31);\n",
+ "y=linspace(-20,20,31);\n",
+ "scatter3(x_darts, y_darts,ones(length(x_darts),1))\n",
+ "xlabel('x position (cm)')\n",
+ "ylabel('y position (cm)')\n",
+ "hold on\n",
+ "[X,Y]=meshgrid(x,y);\n",
+ "view([1,1,1])\n",
+ "\n",
+ "surf(X,Y,gauss2d(X,Y))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 187,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "gauss2d = @(x,y) exp(-((x-0).^2/2/1^2+(y-0).^2/2/5^2));\n",
+ "\n",
+ "x=linspace(-20,20,71);\n",
+ "y=linspace(-20,20,31);\n",
+ "scatter3(x_darts, y_darts,ones(length(x_darts),1))\n",
+ "xlabel('x position (cm)')\n",
+ "ylabel('y position (cm)')\n",
+ "hold on\n",
+ "[X,Y]=meshgrid(x,y);\n",
+ "view([1,1,1])\n",
+ "\n",
+ "surf(X,Y,gauss2d(X,Y))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 190,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "hist(darts(:,2))"
+ ]
+ }
+ ],
+ "metadata": {
+ "celltoolbar": "Slideshow",
+ "kernelspec": {
+ "display_name": "Octave",
+ "language": "octave",
+ "name": "octave"
+ },
+ "language_info": {
+ "file_extension": ".m",
+ "help_links": [
+ {
+ "text": "MetaKernel Magics",
+ "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md"
+ }
+ ],
+ "mimetype": "text/x-octave",
+ "name": "octave",
+ "version": "0.19.14"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/14_stats_and_montecarlo/.ipynb_checkpoints/lecture_16-checkpoint.ipynb b/14_stats_and_montecarlo/.ipynb_checkpoints/lecture_16-checkpoint.ipynb
new file mode 100644
index 0000000..2fd6442
--- /dev/null
+++ b/14_stats_and_montecarlo/.ipynb_checkpoints/lecture_16-checkpoint.ipynb
@@ -0,0 +1,6 @@
+{
+ "cells": [],
+ "metadata": {},
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/14_stats_and_montecarlo/16_stats_and_montecarlo.ipynb b/14_stats_and_montecarlo/16_stats_and_montecarlo.ipynb
new file mode 100644
index 0000000..5482e1b
--- /dev/null
+++ b/14_stats_and_montecarlo/16_stats_and_montecarlo.ipynb
@@ -0,0 +1,20583 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "collapsed": true,
+ "slideshow": {
+ "slide_type": "skip"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "setdefaults"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": true,
+ "slideshow": {
+ "slide_type": "skip"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "%plot --format svg"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "# Statistics and Monte-Carlo Models\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "## Statistics\n",
+ "\n",
+ "How do we describe *precision* and *accuracy*?\n",
+ "\n",
+ "- mean\n",
+ "\n",
+ "- standard deviation\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "## Monte Carlo Simulations\n",
+ "\n",
+ "Monte Carlo models use random numbers to either understand statistics or generate a solution. \n",
+ "\n",
+ "### Example 1:\n",
+ "#### Calculate $\\pi$ with random numbers. \n",
+ "\n",
+ "Assuming we can actually generate random numbers (a topic of philosophical and heated debates) we can populate a unit square with random points and determine the ratio of points inside and outside of a circle.\n",
+ "\n",
+ "\n",
+ "\n",
+ ""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "The ratio of the area of the circle to the square is:\n",
+ "\n",
+ "$\\frac{\\pi r^{2}}{4r^{2}}=\\frac{\\pi}{4}$\n",
+ "\n",
+ "So if we know the fraction of random points that are within the unit circle, then we can calculate $\\pi$\n",
+ "\n",
+ "(number of points in circle)/(total number of points)=$\\pi/4$"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "fragment"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "function our_pi=montecarlopi(N)\n",
+ " % Create random x-y-coordinates\n",
+ "\n",
+ " x=rand(N,1);\n",
+ " y=rand(N,1);\n",
+ " R=sqrt(x.^2+y.^2); % compute radius\n",
+ " num_in_circle=sum(R<1);\n",
+ " total_num_pts =length(R);\n",
+ " our_pi = 4*num_in_circle/total_num_pts;\n",
+ "end\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "mean value for pi = 3.141720\n",
+ "standard deviation is 0.000502\n",
+ "actual pi is 3.141593\n"
+ ]
+ }
+ ],
+ "source": [
+ "test_pi=zeros(10,1);\n",
+ "for i=1:10\n",
+ " test_pi(i)=montecarlopi(10000000);\n",
+ "end\n",
+ "fprintf('mean value for pi = %f\\n',mean(test_pi))\n",
+ "fprintf('standard deviation is %f',std(test_pi))\n",
+ "fprintf('actual pi is %f',pi)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "### Example 2\n",
+ "#### Determine uncertainty in failure stress based on geometry\n",
+ "\n",
+ "In this example, we know that a steel bar will break under 940 MPa tensile stress. The bar is 1 mm by 2 mm with a tolerance of 1 %. What is the range of tensile loads that can be safely applied to the beam?\n",
+ "\n",
+ "$\\sigma_{UTS}=\\frac{F_{fail}}{wh}$\n",
+ "\n",
+ "$F_{fail}=\\sigma_{UTS}wh$"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "ans = 1.8803\n",
+ "ans = 0.021802\n"
+ ]
+ },
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "N=1000;\n",
+ "r=rand(N,1);\n",
+ "wmean=1; % in mm\n",
+ "wmin=wmean-wmean*0.01;\n",
+ "wmax=wmean+wmean*0.01;\n",
+ "hmean=2; % in mm\n",
+ "hmin=hmean-hmean*0.01;\n",
+ "hmax=hmean+hmean*0.01;\n",
+ "\n",
+ "wrand=wmin+(wmax-wmin)*r;\n",
+ "hrand=hmin+(hmax-hmin)*r;\n",
+ "\n",
+ "uts=940; % in N/mm^2=MPa\n",
+ "\n",
+ "Ffail=uts.*wrand.*hrand*1e-3; % force in kN\n",
+ "hist(Ffail,20,1)\n",
+ "xlabel('failure load (kN)')\n",
+ "ylabel('relative counts')\n",
+ "mean(Ffail)\n",
+ "std(Ffail)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "Normally, the tolerance is not a maximum/minimum specification, but instead a normal distribution that describes the standard deviation, or the 68 % confidence interval.\n",
+ "\n",
+ "So instead, we should generate normally distributed dimensions."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "ans = 1.8800\n",
+ "ans = 0.026571\n"
+ ]
+ },
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "N=100000;\n",
+ "wmean=1; % in mm\n",
+ "wstd=wmean*0.01; % standard deviation in mm\n",
+ "hmean=2; % in mm\n",
+ "hstd=hmean*0.01; % standard deviation in mm\n",
+ "\n",
+ "\n",
+ "wrand=normrnd(wmean,wstd,[N,1]);\n",
+ "hrand=normrnd(hmean,hstd,[N,1]);\n",
+ "uts=940; % in N/mm^2=MPa\n",
+ "\n",
+ "Ffail=uts.*wrand.*hrand*1e-3; % force in kN\n",
+ "hist(Ffail,20,1)\n",
+ "xlabel('failure load (kN)')\n",
+ "ylabel('relative counts')\n",
+ "mean(Ffail)\n",
+ "std(Ffail)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "# Thanks"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "# Using data from Dart board experiment"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 173,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "darts=dlmread('compiled_data.csv',',');\n",
+ "x_darts=darts(:,1).*cosd(darts(:,2));\n",
+ "y_darts=darts(:,1).*sind(darts(:,2));\n",
+ "\n",
+ "colormap(colorcube(length(darts(:,3))))\n",
+ "\n",
+ "scatter(x_darts, y_darts, [], darts(:,3))\n",
+ "xlabel('x position (cm)')\n",
+ "ylabel('y position (cm)')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 174,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "mu_x = 0.90447\r\n"
+ ]
+ }
+ ],
+ "source": [
+ "mu_x=mean(x_darts)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "s_x = 4.2747\r\n"
+ ]
+ }
+ ],
+ "source": [
+ "s_x=std(x_darts)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 175,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "mu_y = 0.88450\r\n"
+ ]
+ }
+ ],
+ "source": [
+ "mu_y=mean(y_darts)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 177,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "s_y = 4.6834\r\n"
+ ]
+ }
+ ],
+ "source": [
+ "s_y=std(y_darts)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 180,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "hist(x_darts,30,100)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 182,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "x_vals=linspace(-15,20,30);\n",
+ "hist(x_darts,x_vals,1);\n",
+ "[histFreq, histXout] = hist(x_darts, 30);\n",
+ "binWidth = histXout(2)-histXout(1);\n",
+ "bar(histXout, histFreq/binWidth/sum(histFreq));\n",
+ "pdfnorm = @(x) 1/sqrt(2*s_x^2*pi).*exp(-(x-mu_x).^2/2/s_x^2);\n",
+ "%cdfnorm = @(x) 1/2*(1+erf((x-mu_x)./sqrt(2*s_x^2)));\n",
+ "%hist(x_darts,x_vals,trapz(x,f))%,cdfnorm(max(x_darts))/2)\n",
+ "hold on;\n",
+ "plot(x_vals,pdfnorm(x_vals))\n",
+ "n=2; % n=1, 68% confidence, n=2, 95% confidence, n=3, 99% conf\n",
+ " plot([mu_x+n*s_x,mu_x+n*s_x],[0,0.1],'r-')\n",
+ " plot([mu_x-n*s_x,mu_x-n*s_x],[0,0.1],'r-')\n",
+ "\n",
+ "xlabel('x position (cm)')\n",
+ "ylabel('relative counts')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 183,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "y_vals=linspace(-15,20,30);\n",
+ "hist(y_darts,y_vals,1);\n",
+ "[histFreq, histXout] = hist(y_darts, 30);\n",
+ "binWidth = histXout(2)-histXout(1);\n",
+ "bar(histXout, histFreq/binWidth/sum(histFreq));\n",
+ "pdfnorm = @(x) 1/sqrt(2*s_y^2*pi).*exp(-(x-mu_y).^2/2/s_y^2);\n",
+ "%cdfnorm = @(x) 1/2*(1+erf((x-mu_x)./sqrt(2*s_x^2)));\n",
+ "%hist(x_darts,x_vals,trapz(x,f))%,cdfnorm(max(x_darts))/2)\n",
+ "hold on;\n",
+ "plot(y_vals,pdfnorm(y_vals))\n",
+ "n=2; % n=1, 68% confidence, n=2, 95% confidence, n=3, 99% conf\n",
+ " plot([mu_y+n*s_y,mu_y+n*s_y],[0,0.1],'r-')\n",
+ " plot([mu_y-n*s_y,mu_y-n*s_y],[0,0.1],'r-')\n",
+ "\n",
+ "xlabel('x position (cm)')\n",
+ "ylabel('relative counts')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 76,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "x_exp=empirical_cdf(x_vals,x_darts);\n",
+ "plot(x_vals,x_exp)\n",
+ "hold on;\n",
+ "plot(x_vals,normcdf(x_vals,mu_x,s_x),'k-')\n",
+ "legend('experimental CDF','Normal CDF','Location','SouthEast')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 185,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ "