A Python tool for calculating the variance and standard deviation of mathematical functions with multiple variables, using error propagation theory.
This application computes the variance of a mathematical function by analyzing how uncertainties in input variables propagate through the function. It uses partial derivatives and covariance matrices to provide accurate uncertainty measurements.
The variance calculation is based on the error propagation formula:
var(f) = Σᵢⱼ (∂f/∂xᵢ)(∂f/∂xⱼ) · cov(xᵢ, xⱼ)
Where:
∂f/∂xᵢ
is the partial derivative of function f with respect to variable xᵢ∂f/∂xⱼ
is the partial derivative of function f with respect to variable xâ±¼cov(xáµ¢, xâ±¼)
is the covariance between variables xáµ¢ and xâ±¼- For i = j,
cov(xáµ¢, xáµ¢) = var(xáµ¢)
(variance of variable xáµ¢)
The partial derivatives are computed automatically using SymPy's symbolic differentiation.
- Multi-variable support: Handle functions with up to 10 variables
- Automatic differentiation: Partial derivatives computed symbolically
- Interactive input: Step-by-step data entry with validation
- Comprehensive output: Displays function, variables, variances, covariances, and results
- Data export: Download input data and results as a text file
- Error propagation: Accurate uncertainty calculation using covariance matrices
- Python 3.6 or higher
- NumPy
- SymPy
Install dependencies:
pip install numpy sympy
- Run the application
- Enter the number of variables (maximum 10)
- Input your mathematical function using variable names (a, b, c, etc.)
- Provide values for each variable
- Enter variances for each variable
- Input covariances between variable pairs
- View calculated variance and standard deviation
- Optionally download the results
Input:
Number of variables: 2
Function: a + b
Variable values: a = 1, b = 2
Variances: var(a) = 1, var(b) = 4
Covariances: cov(a,b) = 3
Output:
Function: a + b
Variable values:
a: 1
b: 2
Variances:
a: 1
b: 4
Covariances:
a-b: 3
Variance = 10
Standard deviation = 3.162277660168379
Calculation breakdown:
- ∂f/∂a = 1, ∂f/∂b = 1
- var(f) = (1×1×1) + (1×1×4) + (1×1×3) + (1×1×3) = 1 + 4 + 3 + 3 = 10
This tool is useful for:
- Scientific measurements: Propagating experimental uncertainties
- Engineering calculations: Analyzing measurement errors in complex systems
- Statistical analysis: Understanding how input uncertainties affect results
- Quality control: Assessing precision in manufacturing processes
- Research: Error analysis in mathematical modeling