Matlab Project STAT.
PROBLEM 1: Simulate the resistance and the current across a circuit.
Consider the following circuit
Where V = voltage from a battery source (unit of measure: Volts),
I = Current (unit of measure: Amperes)
And R1, R2, R3 are resistors connected in parallel (unit of measure: Ohms).
When resistors are connected in parallel, the equivalent resistance, Req, can be computed:
By Ohm’s Law,
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Components are designed to perform at a nominal value, however, due to manufacturing inconsistencies all components are subject to variation from its desired value.
Referring to the diagram above, consider the following:
Voltage is specified to be 18 V, tolerance is 0.5 V
Resistors R1 and R2 is specified to be 10 and R3 is specified to be 20 .
The tolerance on R1 and R2 is 0.5 ( of nominal)
The tolerance on R3 is 1.0 ( of it’s nominal)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Simulation of the total resistance, Req, across this circuit.
Steps:
For N = 1000000,
Randomly generate N values for R1, R2, R3,
Let R1 ~ Unif [9.5,10.5]; R2 ~ Unif [9.5,10.5]; and R3 ~ Unif [19.0, 21.0].
Matlab command:
random(‘unif’,A,B,[N,1]); generates N values from a Unif [A,B] distribution.
After you’ve generated your R1, R2, and R3 vectors, use equation on page 1 to generate Req.
You might consider doing this in two steps:
Let , then
Matlab:
To perform operations on vector elements, put a period “.” before the desired operation:
A=1./R1+1./R2+1./R3; A will be a Nx1 vector.
Now that you’ve got A, use same syntax to produce the Req vector.
For you to hand in:
a. Well labelled histograms of R1, R2, and R3.
b. A well labelled histogram of Req.
c. Based on the nominal values of R1, R2, and R3, compute (by hand) the theoretical value for Req.
d. Provide the mean and standard deviation of your simulated Req results.
e. The mean of your simulated Req results is a point estimate for the true mean of Req.
How does the mean Req from your simulation compare to the theoretical value of Req?
f. For a very large sample such as this, the 95% confidence interval for the true mean is:
Mean of simulation 1.96*(standard deviation of simulation)/
Compute and provide this confidence interval for the true mean of Req. Is the theoretical value
for Req contained in this interval?
g. Provide supporting matlab code.
2. Simulation of the current, I, across this circuit.
Steps:
Randomly generate the Voltage, V, where V ~ Unif [17.5,18.5].
Using your simulated Req vector from part 1 and the voltage, V, create the current vector, I.
The equation relating I, V, and Req is on the from page.
For you to hand in:
a. A well labelled histogram of I.
b. Based on the nominal value of V and theoretical value for Req, compute (by hand) the
theoretical value of I.
c. Provide the mean current and the standard deviation based on your simulation. How does the
mean of your simulation compare to the theoretical value of I?
d. Find the 95% prediction interval for the current across this system by lopping off the smallest
2.5% of the values, find this cut point, then lop off the largest 2.5% of the values, determine
this cut point. Thus 95% of your simulated values fall between these two cut points.
Matlab:
prctile(I,2.5); will provide the cut point between the lowest 2.5% of values and the
remaining 97.5% of values.
Prctile(I,97.5); will provide the cut point between the lowest 97.5% of values and the
upper 2.5% of values.
e. Provide supporting matlab code.
PROBLEM 2: Simple Linear Regression.
Background: Work through Matlab Exercise 2 (posted with this assignment). Steps #8 and #9 pertain to this problem.
Consider the following sample of ordered pairs (x, y) where
y = the purity of oxygen produced in a chemical distillation process, and
x = the percentage of hydrocarbons that are present in the main condenser of the distillation unit.
|
Observation Number |
Hydrocarbon Level; x (in %) |
Purity y (in %) |
|
Observation Number |
Hydrocarbon Level; x (in %) |
Purity y (in %) |
|
1 |
0.99 |
90.01 |
|
11 |
1.19 |
93.65 |
|
2 |
1.02 |
89.05 |
|
12 |
1.15 |
92.52 |
|
3 |
1.15 |
91.43 |
|
13 |
0.98 |
90.56 |
|
4 |
1.29 |
93.74 |
|
14 |
1.01 |
89.54 |
|
5 |
1.46 |
96.73 |
|
15 |
1.11 |
89.85 |
|
6 |
1.36 |
94.45 |
|
16 |
1.2 |
90.39 |
|
7 |
0.87 |
87.59 |
|
17 |
1.26 |
93.25 |
|
8 |
1.23 |
91.77 |
|
18 |
1.32 |
93.41 |
|
9 |
1.55 |
99.42 |
|
19 |
1.43 |
94.98 |
|
10 |
1.4 |
93.65 |
|
20 |
0.95 |
87.33 |
0. Enter above data either as a single 20x2 matrix or as two 20x1 vectors. Be sure to preserve
the ordering of the pairs.
a. Create a scatterplot of this data. Label both the x and y axis’ and title the graph “scatterplot”
Labels can be added on the graph itself by choosing “Insert” drop down menu.
b. Determine the correlation coefficient.
The corrcoef(x,y) command produces a 2x2 matrix with 1’s down the principle diagonal
Cell 1,1 provides the correlation of x with itself and cell 2,2 is the correlation of y with itself
(both of which are 1). Cell 2,1 provides the correlation between x and y, cell 1,2 provides the
correlation between y and x (both, of course would be the same)
c. Find the equation of the least square regression line, and determine the p-value of the slope term . To generate the line and obtain the p-value you should use the fitlm command (refer to Matlab exercise 2). Using the 5% Significance Level, if the p-value < .05, then the linear model is statistically significant.
d. You can also display the regression equation on your scatterplot by selecting “Tools” drop down menu, select “basic fitting”, linear.
e. If your regression model is statistically significant then use it to estimate Oxygen purity (in
%) when the hydrocarbon level in the main condenser of the distillation unit is 1%.