Calculating the Sensitivity of a Transfer Function to Independant Variables Using the Taylor Series

In this post we discussed the use of the Taylor Series to evaluate the propagated uncertainties in measurements to a calculated result. We can also use a similar approach to determine the sensitivity of a transfer function to know perturbations in the independent variables.

Frustum_750In this case we will look at the volume of a right conical frustum or a truncated cone. The volume can be calculated from the three variables: , and shown in the figure. The volume is given as

The first step is to calculate the partial derivatives of with respect to the independent variables.

The total uncertainty in the volume, , is given in terms of the uncertainties in the independent variables, , and .

Each term of the form is the contribution to the total perturbation of the function by the perturbation of the independent variable, . Therefore we can calculate the sensitivities, , of the volume to small changes in each of the three variables , and , by calculating the percentage contribution of each term to the total perturbation. Typically, we wish to also define the direction that the pertubations in the independent variables will affect the total, so we remove the absolute values and evaluate the partial derivatives while maintaining their signs.

It is also evident that .


Example:

Suppose we have a design for a conical frustum with nominal dimensions of 0.500 in, 0.375 in and 1.250 in. Our manufacturing process can hold to ±.002 in, to ± .007 in and to ± .010 in. We then have the following inputs to our formulae.

From this we can calculate the nominal volume of our manufactured part.

Next we can calculate the partial derivatives.

And having the partial derivatives, we can calculate the total propagated uncertainty in the nominal volume.

From this we can obtain the predicted volume of the manufactured part subject to the manufacturing tolerances: 0.757 ± .021 in3. We can then calculate the relative sensitivity of the total volume to the manufacturing tolerances specified.

It is important to note that these results are only valid for the initial conditions specified. If the nominal values for the dimensions or the tolerances change, both the uncertainties and sensitivities will change.


Caveat lector — All work and ideas presented here may not be accurate and should be verified before application.

Using ‘sed’ to bulk edit text files

Google Analytics provides free yet super-sophisticated website tracking and statistics. Unfortunately, it requires that the following code snippet be inserted into every web page immediately before the </body> tag.


<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-12232036-2");
pageTracker._trackPageview();
} catch(err) {}</script>

Now with a static website such as www.elizabethpassela.com, that’s a lot of pages to manually update. What we’d like is a way to perform a bulk insert of the required text on all .htm files in the webroot directory. Here’s where ‘sed’ comes to the rescue.

First task is to create a ‘sed’ script file called sed.cmd. The first line includes the search string </body> and the /i “insert” option which tells ‘sed’ to insert the following text before the </body> string. The ” at the end of each line is needed to tell ‘sed’ that another line exists in the script, sort of a continuation operator. Since the ‘/’ character was used as the separator for the script command, all ‘/’ characters which are part of the operand need to be escaped with ”.


/</body>/i
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-12232036-2");
pageTracker._trackPageview();
} catch(err) {}</script>

Finally, execute the following command to insert the text into all .htm files. The '-i' tells sed to operate on the files in-place (if 'sed' is run without the '-i' option, the output will be sent to stdout which is good for testing).


# sed -i -f ~cbattles/sed.cmd *.htm

A similar approach can be used for replacing and appending text as well as inserting. Additionally, the 'find command can be piped to 'sed' to operate on selective files.


Caveat lector — All work and ideas presented here may not be accurate and should be verified before application.

Word wrap inside
 block

In the Arras theme that I use, text contained within a <pre></pre> block was not being wrapped, causing formatting problems in I.E. (e.g. the sidebar would be forced below the post) and reducing readability. A solution was found on this site. For my solution, adding the following code to the end of /wp-content/themes/arras-theme/css/styles/default.css solved this problem quickly and easily.


pre {
 overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */
 white-space: pre-wrap; /* css-3 */
 white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
 white-space: -pre-wrap; /* Opera 4-6 */
 white-space: -o-pre-wrap; /* Opera 7 */
 /* width: 99%; */
 word-wrap: break-word; /* Internet Explorer 5.5+ */
}

Manually Backing Up WordPress

To backup, first create a tarball of the website


[root@Kepler Cbattles]# tar -cvjf WordPress.tar.bz2 ./blog

and then dump the MySQL database


[root@Kepler Cbattles]# mysqldump --add-drop-table -h localhost -u wordpress -p wordpress | bzip2 -c > blog.bak.sql.bz2

Put the two files in a safe place. Easy.

Security Note: These files are created in the webroot directory. This means that they are accessible by anyone. Either create them in a safe location or move them after creation.


Caveat lector — All work and ideas presented here may not be accurate and should be verified before application.

Basic R — Descriptive Statistics of Univariate Data

This is a basic introductory look at using R for generating descriptive statistics of a univariate data set. Here, we will use the historical dataset of Michelson’s experiment to determine the speed of light in air provided as a an ASCII file with header content and the observed speed of light for 100 trials.

We need to first read the data into R. Since the data is in a properly formatted ASCII file, we only need to tell R to ignore the first 60 lines, which is header information. R will then import the data into a list of class data.frame.


>C <- read.table("Michelso.dat",skip=60)

We can take a look at the dataset by simply typing the dataset name at the prompt. Here you can see that R automatically assigned the variable V1 to the data.


> C
        V1
1   299.85
2   299.74
3   299.90
4   300.07
...

The summary() command in R provides the summary statistics: MIn, 1st Q, Median, Mean, 3rd Q and Max. We call this function with the argument 'C$V1' which tells R to act on the named variable, V1, in the data.frame C. (The options commands set the output number formatting to something realistic.)


> options(scipen=100)
> options(digits=10)
> summary(C$V1)
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
299.6200 299.8075 299.8500 299.8524 299.8925 300.0700 

Standard deviation, trimmed mean and number of data points can be obtained individually.


>sd(C$V1)
[1] 0.07901054782
>mean(C$V1,trim=0.05)
[1] 299.8528889
>length(C$V1)
[1] 100

If we want to get skewness and kurtosis we'll need the fBasics package installed


> install.packages("fBasics")
> library(fBasics)
...
>skewness(C$V1, method="moment")
[1] -0.01798640563
attr(,"method")
[1] "moment"
>kurtosis(C$V1, method="moment")
[1] 3.198586275
attr(,"method")
[1] "moment"

To determine confidence intervals on the mean, we can use the one sample t-test. We can ignore the mean value to test against since in our case it is not known (or relevant for confidence interval estimation)


> t.test(C$V1, conf.level=0.99)

	One Sample t-test

data:  C$V1 
t = 37950.9329, df = 99, p-value < 0.00000000000000022
alternative hypothesis: true mean is not equal to 0 
99 percent confidence interval:
 299.8316486 299.8731514 
sample estimates:
mean of x 
 299.8524

Another method for obtaining much of this information in a single step can be found in the stat.desc() function from the pastecs package.


> install.packages("pastecs")
> library(pastecs)
...
> options(scipen=100)
> options(digits=4)
> stat.desc(C)
                        V1
nbr.val        100.0000000
nbr.null         0.0000000
nbr.na           0.0000000
min            299.6200000
max            300.0700000
range            0.4500000
sum          29985.2400000
median         299.8500000
mean           299.8524000
SE.mean          0.0079011
CI.mean.0.95     0.0156774
var              0.0062427
std.dev          0.0790105
coef.var         0.0002635

We'll look at the generation of some standard statistical plots for exploratory data analysis in a future post.


Caveat lector — All work and ideas presented here may not be accurate and should be verified before application.