Numeric error propagation

From Rosetta Code
Revision as of 02:51, 30 July 2011 by rosettacode>Paddy3118 (New draft task.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Numeric error propagation is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

If f, a, and b are values with uncertainties σf, σa, and σb. and c is a constant; then if f is derived from a, b, and c in the following ways, then σf can be calculated as follows:

Addition/Subtraction
  • If f = a ± c, or f = c ± a then σf = σa
  • If f = a ± b then σf2 = σa2 + σb2
Multiplication/Division
  • If f = ca or f = ac then σf = cσa
  • If f = ab or f = a / b then σf2 = f2( (σa / a)2 + (σb / b)2)
Exponentiation
  • If f = ac then σf = fc(σa / a)
Task details
  1. Add an uncertain number type to your language that can support addition, subtraction, multiplication, division, and exponentiation between numbers with an associated error term together with 'normal' floating point numbers without an associated error term.
    Implement enough functionality to perform the following calculations.
  2. Given coordinates and their errors:
x1 = 100 ± 1.1
x2 = 200 ± 2.2
y1 = 50 ± 1.2
y2 = 100 ± 2.3
  1. if point p1 is located (x1, y1) and p2 is at (x2, y2); calculate the distance between the two points using the formula
    d = √((x1 - x2)2 + (y1 - y2)2)
  2. Print and display both d and its error.
References