Steffen Müller >
App-ErrorCalculator-1.02 >
App::ErrorCalculator

Module Version: 1.02
App::ErrorCalculator - Calculations with Gaussian Error Propagation

# You can use the 'errorcalculator' script instead. require App::ErrorCalculator; App::ErrorCalculator->run(); # Using the script: # errorcalculator

`errorcalculator`

and its implementing Perl module `App::ErrorCalculator`

is a Gtk2 tool that lets you do calculations with automatic error propagation.

Start the script, enter a function into the function entry field, select an input file, select an output file and hit the *Run Calculation* button to have all data in the input field processed according to the function and written to the output file.

Functions should consist of a function name followed by an equals sign and a function body. All identifiers (both the function name and all variables in the function body) should start with a letter. They may contain letters, numbers and underscores.

The function body may contain any number of constants, variables, operators, functions and parenthesis. The exact syntax can be obtained by reading the manual page for Math::Symbolic::Parser. Arithmetic operators (`+ - * / ^`

) are supported. The caret indicates exponentiation. Trigonometric, inverse trigonometric and hyperbolic functions are implemented (`sin cos tan cot asin acos atan acot sinh cosh asinh acoth`

). `log`

indicates a natural logarithm.

Additionally, you may include derivatives in the formula which will be evaluated (analytically) for you. The syntax for this is: `partial_derivative(a * x + b, x)`

. (Would evaluate to `a`

.)

In order to allow for errors in constants, the program uses the Math::SymbolicX::Error parser extension: use the `error(1 +/- 0.2)`

function to include constants with associated uncertainties in your formulas.

The input files may be of any format recognized by the Spreadsheet::Read module. That means: Excel sheets, OpenOffice (1.0) spreadsheets, CSV (comma separated values) text files, etc.

The program reads tabular data from the spreadsheet file. It expects each column to contain the data for one variable in the formula.

a, b, c 1, 2, 3 4, 5, 6 7, 8, 9

This would assign `1`

to the variable `a`

, `2`

to `b`

and `3`

to `c`

and then evaluate the formula with those values. The result would be written to the first data line of the output file. Then, the data in the next row will be used and so on. If a column is missing data, it is assumed to be zero.

Since this is about errors, you can declare any number of errors to the numbers as demonstrated below:

a, a_1, a_2, b, b_1 1, 0.2, 0.1, 2, 0.3 4, 0.3, 0.3, 5, 0.6 7, 0.4, 0,1, 8, 0.9

Apart from dropping `c`

for brevity, this example input adds columns for the errors of `a`

and `b`

. `a`

has two errors: `a_1`

and `a_2`

. `b`

only has one error `b_1`

which corresponds to the error `a_1`

. When calculating, `a`

will be used as `1 +/- 0.2 +/- 0.1`

in the first calculation and `b`

as `2 +/- 0.3 +/- 0`

. The error propagation is implemented using Number::WithError so that's where you go for details.

The output file will be a CSV file similar to the input examples above.

"a", "a_1", "a_2", "x", "x_1", "x_2" 1, "0.1", "1.1", 10, "0.1", "1.1" 2, "0.2", "1.2", 11, "0.2", "1.2" 3, "0.3", "1.3", 12, "0.3", "1.3" 4, "0.4", "1.4", 13, "0.4", "1.4" 5, "0.5", "1.5", 14, "0.5", "1.5"

f = a * x^2

"f", "f_1", "f_2" "1.0e+02", "1.0e+02", "1.0e+02" "2.4e+02", "1.3e+02", "1.3e+02" "4.3e+02", "1.6e+02", "1.6e+02" "6.8e+02", "2.0e+02", "2.0e+02" "9.8e+02", "2.4e+02", "2.4e+02"

Just load the module with `require App::ErrorCalculator`

and then run

App::ErrorCalculator->run;

New versions of this module can be found on http://steffen-mueller.net or CPAN.

Math::Symbolic implements the formula parser, compiler and evaluator. (See also Math::Symbolic::Parser and Math::Symbolic::Compiler.)

Number::WithError does the actual error propagation.

Gtk2 offers the GUI.

Steffen Mueller, <particles-module at steffen-mueller dot net<gt>

Copyright (C) 2006 by Steffen Mueller

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.1 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: