Applications of the ScientificErrorAnalysis Package
The ScientificErrorAnalysis package provides representation and construction of numerical quantities that have a value and associated error, which is a measure of the degree of precision to which the quantity's value is known. Calculations of error analysis can be performed with these quantities.
Initialization
restart
withScientificConstants:withScientificErrorAnalysis:
Specification of Quantities with Error
The same quantity-with-error can be entered three different ways.
Quantity⁡20.0,0.1
Quantity⁡20.0,0.005,'relative'
Quantity⁡20.0,0.1000
Quantity⁡20.0,1,'uld'
Other examples:
Quantity⁡3.4ⅇ15, 0.2ⅇ15
Quantity⁡3.4⁢1015,2.⁢1014
Quantity⁡5.1ⅇ−20,0.1,'relative'
Quantity⁡5.1⁢10-20,5.1⁢10-21
Quantity⁡4.2012883,12,'uld'
Quantity⁡4.2012883,0.0000012
Important: These quantities do not represent intervals in which possible values must be contained - they represent unknown values with central tendency. See any text on error analysis for the physical sciences or engineering.
A Note about the Display of Maple Floating-Point Numbers
If a floating-point number is not displayed in scientific notation, it may not be apparent whether trailing zeros are significant figures.
Quantity⁡4.0ⅇ2,1,'uld'
Quantity⁡400.,10.
SFloatMantissa⁡GetValue⁡,SFloatMantissa⁡GetError⁡
40,1
Simple Error Analysis - Propagation of Errors
Errors can be propagated through calculations by using the combine/errors command.
q1≔Quantity10.0,1.0
q1:=ScientificErrorAnalysis:-Quantity⁡10.0,1.0
q2≔Quantity20.0,3.0
q2:=ScientificErrorAnalysis:-Quantity⁡20.0,3.0
Error in the sum of the above two quantities:
combine⁡q1+q2,'errors'
ScientificErrorAnalysis:-Quantity⁡30.0,3.162277660
Relative error in their sum:
GetError⁡GetValue⁡
0.1054092553
Error in their difference:
combine⁡q2−q1,'errors'
ScientificErrorAnalysis:-Quantity⁡10.0,3.162277660
Relative error in their difference:
0.3162277660
As expected, the relative error in the difference is greater than that in the sum.
Error in the product of the above two quantities:
combine⁡q1⁢q2,'errors'
ScientificErrorAnalysis:-Quantity⁡200.00,36.05551275
Relative error in their product:
0.1802775638
Error in their quotient:
combine⁡q2q1,'errors'
ScientificErrorAnalysis:-Quantity⁡2.000000000,0.3605551275
Relative error in their quotient:
As expected, the relative errors in the product and quotient are the same.
Error in a power:
combine⁡q12,'errors'
ScientificErrorAnalysis:-Quantity⁡100.00,20.00000000
Error in differentiable functions:
combine⁡sin⁡q1,'errors'
ScientificErrorAnalysis:-Quantity⁡−0.5440211109,0.8390715291
combine⁡ⅇq1q2,'errors'
ScientificErrorAnalysis:-Quantity⁡1.648721271,0.1486137271
Important: The above calculations are not interval arithmetic, and the quantities involved do not represent intervals in which values must be contained.
The Formulae of Error Propagation
The usual expressions for error propagation through simple functions are easily obtained.
e1≔Quantityx,delx
e1:=ScientificErrorAnalysis:-Quantity⁡x,delx
e2≔Quantityy,dely
e2:=ScientificErrorAnalysis:-Quantity⁡y,dely
Error in a sum:
combine⁡e1+e2,'errors'
ScientificErrorAnalysis:-Quantity⁡x+y,dely2+delx2
Error in a product:
combine⁡e1⁢e2,'errors'
ScientificErrorAnalysis:-Quantity⁡x⁢y,x2⁢dely2+y2⁢delx2
Relative error2 in the product:
expand⁡GetError⁡2GetValue⁡2
dely2y2+delx2x2
Error in a square:
combine⁡e12,'errors'
ScientificErrorAnalysis:-Quantity⁡x2,2⁢x2⁢delx2
General Formula
The general formula for the error σy in y, where y is a function of variables xi is:
σy2=∑i=1N∂∂xi⁢y2⁢σxi2
where σxi is the error in xi and the partials are evaluated at the central values of the xi .
With covariances σxi,xj taken into account, the formula is:
σy2=∑i=1N∂∂xi⁢y2⁢σxi2+2⁢∑i=1N−1∑j=i+1N∂∂xi⁢y⁢∂∂xj⁢y⁢σxi,xj
The covariance σxi,xj may be expressed in terms of the correlation rxi,xj and errors σxi, σxj as follows:
σxi,xj=rxi,xj⁢σxi⁢σxj
Working with Rounding Rules
Introduction
The initial default rounding rule is digits, for which no rounding is performed.
We can explicitly round a Quantity( ) object:
ApplyRule⁡,round2
ScientificErrorAnalysis:-Quantity⁡30.0,3.2
specify a rounding rule in combine/errors:
combine⁡q1+q2,'errors','rule'=round2
combine⁡q1⁢⋅ q2,'errors','rule'=round2
ScientificErrorAnalysis:-Quantity⁡200.,36.
combine⁡q12,'errors','rule'=round2
ScientificErrorAnalysis:-Quantity⁡100.,20.
or change the default rounding rule using the UseRule function.
UseRule⁡round2
combine⁡q1 ⋅⁢q2,'errors'
UseRule⁡digits
Another Note about Floating-Point Numbers
Quantity23900.0,1854.0
ScientificErrorAnalysis:-Quantity⁡23900.0,1854.0
ApplyRule%, round2
ScientificErrorAnalysis:-Quantity⁡23900.,1900.
239,19
Adding a New Rounding Rule
The rounding rule round3g[n] rounds the error to n figures for a significant figure of 3 or greater and n+1 figures for a significant figure of 1 or 2. Here, we add a similar rule round2g[n], which rounds the error to n figures for a significant figure of 2 or greater and n+1 figures for a significant figure of 1.
AddRule⁡round2g=procx,ylocalxp,yp,n;ifnottypeprocname,'indexed'thenerror `round2g` must be indexed;end if;n:=opprocname;ifnottypen,'posint'thenerror invalid index to `round2g`;end if;xp,yp:=evalfx,evalfy;ifiquoSFloatMantissa⁡yp,10^ilog10⁡SFloatMantissa⁡yp<2thenn:=n+1;end if;`if`xp≠0,evalfn+ilog10⁡SFloatMantissa⁡xp − ilog10⁡SFloatMantissa⁡yp+SFloatExponent⁡xp − SFloatExponent⁡ypxp,Float0,−1,evalfnyp;end proc
We can use the new rule round2g[n].
HasRule⁡round2g
true
Quantity11.22,2.3
ScientificErrorAnalysis:-Quantity⁡11.22,2.3
ApplyRule⁡,round2g1
ScientificErrorAnalysis:-Quantity⁡11.,2.
Quantity11.22,1.3
ScientificErrorAnalysis:-Quantity⁡11.22,1.3
ScientificErrorAnalysis:-Quantity⁡11.2,1.3
Error Analysis with Physical Constants
A Simple Experiment
The period of oscillation T of a simple pendulum for small amplitude is given by:
T=2⁢π⁢Lg
where g is the standard acceleration of gravity and L is the length of the string of the pendulum (or, more precisely, the distance from the point of suspension to the center of the pendulum bob).
A student constructs a pendulum to determine a value for g. The student measures L to be 153.2 centimeters (cm). It is decided that the uncertainty in this measurement is primarily due to the difficulty in measuring L to the center of the bob, and that this uncertainty is about plus or minus 2 millimeters (mm). (In other words, it is estimated that the measurement is probably within 2 millimeters of the correct value.) Thus, L is taken to be 153.2 +/- 0.2 centimeters. In standard units:
Lq≔Quantity1.532,2,'uld'
Lq:=ScientificErrorAnalysis:-Quantity⁡1.532,0.002
Now, the student sets the pendulum swinging with a small amplitude (a few centimeters). Using a stopwatch, the student measures the time for 30 oscillations to be 75.3 seconds (s). The uncertainty in this measurement is due to the human reaction time in operating the stopwatch, and so the time measurement is taken to be 75.3 +/- 0.5 seconds.
t30≔Quantity75.3,0.5
t30:=ScientificErrorAnalysis:-Quantity⁡75.3,0.5
Because the number of oscillations (30) is exact, the period of a single oscillation is:
Tq:=combine⁡t3030,'errors',rule=round2
Tq:=ScientificErrorAnalysis:-Quantity⁡2.510,0.017
The previous formula rearranges to:
g=4⁢π2⁢LT2
and so, the student calculates the experimentally determined value of g to be:
combine⁡4⁢3.14162⁢LqTq2,'errors',rule=round2
ScientificErrorAnalysis:-Quantity⁡9.60,0.13
The accepted value of g is:
evalf⁡Constant⁡g
9.80665
Assuming the error in the experimental value represents a standard deviation, the accepted value thus lies farther than one standard deviation from the experimental central value. The student then must decide whether to repeat the experiment, or consider possibly overlooked sources of measurement error.
Another Example
A sample of a gas is measured to have a volume of 20.3 liters (L), pressure of 105 kilopascals (kPa), and temperature of 297 kelvins (K). If all the measurements have uncertainty of 1%, what is the value and uncertainty of the number of moles in the sample?
The ideal gas law is:
P⁢V=n⁢R⁢T
where P is pressure, V is volume, T is temperature, and R is the ideal gas constant.
Constructing quantities-with-error for P, V, and T in standard units:
Pq≔Quantity105e3,0.01,'relative'
Pq:=ScientificErrorAnalysis:-Quantity⁡1.05⁢105,1050.
Vq≔Quantity20.3ⅇ−3,0.01,'relative'
Vq:=ScientificErrorAnalysis:-Quantity⁡0.0203,0.000203
Tq≔Quantity297.0,0.01,'relative'
Tq:=ScientificErrorAnalysis:-Quantity⁡297.0,2.970
Thus, the number of moles n is:
combine⁡Pq⁢VqConstant⁡R⁢Tq,'errors','rule'=round2
ScientificErrorAnalysis:-Quantity⁡0.863,0.015
Thus, the sample has 0.863 moles (mol) of gas molecules, with a relative error of:
GetError⁡GetValue
0.01738122827
or about 2%.
Working at higher Digits
Some physical constants have their values determined to more than 10 significant figures, hence calculations involving these objects at the default setting of Digits may result in a loss of precision. If more precision is desired, Digits may be set to a higher value, 15 for example.
GetConstant⁡R∞
Rydberg_constant,symbol=R∞,value=1.0973731568549⁢107,uncertainty=0.000083,units=1m
combine⁡ConstantR∞⁢⋅ Constantc,'errors','rule=round2'
ScientificErrorAnalysis:-Quantity⁡3.289841961⁢1015,25000.
Digits:=15:
ScientificErrorAnalysis:-Quantity⁡3.289841960368⁢1015,25000.
Digits≔10:
Error in a Derived Physical Constant
Let us examine the formula for the electron mass.
GetConstant⁡me
electron_mass,symbol=me,derive=2⁢R∞⁢hc⁢α2
As a demonstration, we manually construct the same expression using individual physical constant objects.
e3:=2⁢Constant⁡R∞⁢Constant⁡hConstant⁡c⁢Constant⁡α2
Propagating the errors gives us:
combine⁡e3,'errors','rule=round2'
ScientificErrorAnalysis:-Quantity⁡9.10938188⁢10-31,7.2⁢10-38
The above calculation is similar to the method ScientificConstants and ScientificErrorAnalysis use internally.
GetValue,GetError⁡Constant⁡me
9.109381882⁢10-31,7.179221838⁢10-38
ApplyRule⁡Quantity,'round2'
Return to ScientificErrorAnalysis
Return to Index for Example Worksheets
Download Help Document