Monte Carlo B201196ME

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Department of Mechanical

Engineering, NIT Calicut


ME3112: Metrology and Instrumentation

Name: GAIKWAD PRATHAMESH SANDIP


Roll No: B201196ME
Batch: ME04
GROUP: I
Contents:
• Problem Statement
• Approach
• General Steps for Monte Carlo
Simulation
• Methodology
• Solution Code
• Code terminologies
Problem Statement: (problem no. 9)

A gauge block with a nominal length of 10 mm is measured


on a length measuring machine that is read out by a laser
interferometer. The uncertainty of the laser interferometer is
negligible. The laser interferometer is not corrected for the
linear expansion coefficient. The repeated measurements are
as follows.

Measurement 1 2 3 4 5
Number

Size/mm 10.0001 10.0001 10.0001 10.0002 10.0001

The room temperature is specified as (21 ± 1) °C. Assume a


rectangular distribution for the temperature. The linear
thermal expansion coefficient of the gauge block is specified
as α = (11.5 ± 1) x10–6 K–1. Assume a rectangular
distribution for the linear thermal expansion coefficient. The
model equation for the gauge block length at 20 °C is

L =L0(1+α(t-t0)).

Calculate the 95% confidence interval for the gauge block


length at 20 °C using a Monte Carlo method with 2x105 trials.
Plot histogram representing the resulting PDF for gauge block
length at 20 °C estimated by Monte Carlo simulation
Approach: Monte Carlo Method

MONTE CARLO SIMULATION

It is a method for the propagation of distributions by


performing random sampling from probability distributions.
The Monte Carlo methodology as presented by the GUM
Supplement 1 involves the propagation of the distributions of
the input sources of uncertainty by using the model to provide
the distribution of the output.
This process is illustrated in Figure below in comparison
with the propagation of uncertainties used by the GUM.

Above figure shows an illustration representing the


propagation of uncertainties in this case, three input quantities
are presented x1, x2 and x3 along with their respective
uncertainties u(x1), u(x2) and u(x3). Only the main moments
(expectation and standard deviation) of the input quantities are
used in the propagation and thus a certain amount of
information is lost in propagating distributions (Fig.1(b)) no
approximations are made and the whole information
contained on the input distributions are propagated to the
output.

General Steps for Monte Carlo Simulation:


1. make M (the number of Monte Carlo trials) draws from
the PDF for each input quantity Xi (or the joint PDF for
X);
2. make M (Monte Carlo trials) corresponding evaluations
of the model;
3. sort the resulting M model values into non-decreasing
order.
4. determine the coverage interval based on level of
confidence required

Steps involved in uncertainty analysis using Monte


Carlo Method:
1. Identify the input quantities and their probability
distributions.
2. Determine the mathematical relationship between the
input quantities.
3. Select the most appropriate probability density functions
(PDFs) for each input quantity, making sure not to
incorporate more information than what is available.
4. Choose a number of Monte Carlo trials, with more
simulation trials leading to better results.
5. Generate random values for each input quantity using
their respective PDFs.
6. Calculate the corresponding output values using the
mathematical relationship between the input quantities.
7. Repeat steps 5 and 6 for the chosen number of Monte
Carlo trials.
8. Calculate the estimated value of the output quantity as
the average of the generated values.
9. Calculate the standard uncertainty as the standard
deviation of the generated values.
10. Choose a coverage probability (usually 95%) and
calculate the endpoints for the selected coverage interval.
11. Report the estimated value, standard uncertainty,
chosen coverage probability, and endpoints.

Methodology:
1. Python is used for Monte Carlo Simulation.
2. A total of 200,000 trials were selected for the simulation.
3. The NumPy library in Python is used which provides
various mathematical functions and allows generating
random numbers based on different distributions
4. The matplotlib library in Python is used to plot histogram
figures of 200,000 trials for better visualization of the
simulation results.
Solution Code
(Language – python)

# Monte Carlo simulation #Number of trails are 200000


# Number of trails are 200000
# we have used numpy for gaenerating random values based on uniform distribution, traingular distribution
, normal distribution
# math library is for doing mathematical calclations like sqyuare root,mean,min,max
# matplotlib library is to plot histogram figures

import numpy as np
import math
import matplotlib.pyplot as plt
import random

# define the number of trials


N=200000

# temperature variation of (t-to)


# rectangular distribution
t_to = np.random.uniform(2.000, 0.000, size=N)

# linear thermal expansion coefficient


# rectangular distribution
alpha = np.random.uniform(10.500, 12.500, size=N)

# gauge block length based on calibration at 20 °C


# Gaussian distribution
L0 = np.random.normal(10.00012, 4.4721359549892E-5, N)

# model equation
# L =L0(1+α(t-t0))
L = L0*(1+alpha*1e-6*t_to)

L.sort()
# Mean, Uncertainty, Confidence Interval with 100 % coverage interval
print("Mean: "+str(L.mean()))
print("Uncertainty: "+str(L.std()))
print("Confidence Interval: "+str(L.min())+" , "+str(L.max()))
# histogram figure
plt.hist(L,bins=np.linspace(L.min(),L.max(),250))
plt.grid()
plt.show()

Output For 100% Coverage Interval is:

Mean: 10.000235055517773 mm
Uncertainty: 8.015992071846568e-05 mm
Confidence Interval: 9.999958949698739 , 10.000518354025193 mm

interval = np.percentile(L, [2.5, 97.5])

# Mean, Uncertainty, Confidence Interval with 95% coverage interval


print("Mean: "+str(interval.mean()))
print("Uncertainty: "+str(interval.std()))
print("Confidence Interval: "+str(interval.min())+" ,
"+str(interval.max()))
# histogram figure
plt.hist(L,bins=np.linspace(L.min(),L.max(),250))
plt.xlabel('Gauge block length at 21 °C (mm)')
plt.ylabel('PDF')
plt.axvline(interval[0], color='r', label='95% CI')
plt.axvline(interval[1], color='r')
plt.legend()
plt.grid()
plt.show()

print('95% confidence interval:', interval)

Output For 95% Coverage Interval is:

Mean: 10.00023590835108 mm
Uncertainty: 0.00014931725097522275 mm
Confidence Interval: 10.000086591100104 , 10.000385225602054 mm
The utilization of Python code facilitated the
implementation of the Monte Carlo Simulation, which
provided the necessary outcomes of the best approximation
and uncertainty. Interestingly, these results were consistent
even with varying random values generated.
Moreover, the histogram produced by the simulation had
a resemblance to the normal distribution curve obtained from
other methods, such as GUM. With the inclusion of the
probability distribution of input uncertainties, the Monte Carlo
method is anticipated to produce more accurate results.
While the computation of 200,000 iterations may seem
burdensome, it can be conveniently executed using various
software tools, such as MATLAB, Excel, and Python, which
was used in this instance. Consequently, the Monte Carlo
method is deemed practical and more precise for calculating
measurement uncertainties.

Code terminologies:

1. nump.random.uniform() function is used to generate


uniform distribution with given minimum and maximum
value
2. nump.random.normal() function is used to generate
normal(gaussian) distribution with given mean and
standard deviation value

histograms have been plotted for visualization for both


confidence percentages. In histogram function, bins are given
with 250 which ensures good resolution of the Histogram.
Finally, outputs are:

Best Estimate of gauge block length at room


temperature = 10.00023590835108 mm

Coverage interval with 100% confidence:


Standard measurement uncertainty = 8.015992071846568e-05 mm
Lower limit = 9.999958949698739 mm
Upper limit = 10.000518354025193 mm

Coverage interval with 95% confidence:


Standard measurement uncertainty = 10.00023590835108 mm
Lower limit = 10.000086591100104 mm
Upper limit = 10.000385225602054 mm

Thank You!

You might also like