Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
I am new to mathcad and I was searching for a function to calculate the amount of error (relative/absolute) in any formula.
At my physics study we need to be able to determine this for any formula, but sometimes it takes really large amounts of pages to write them and hours to double check them.
There are a few simple rules for creating formula's which determine the error:
1)When adding or substracting, the total error is the addition of the two absolute error, example:
Formula:
R_total = R_1 - R_2 + R_3
error formula:
total_error_in_R = error_in_R_1 + error_in_R_2 + error_in_R_3
2)When multiplying or dividing, you add the relative errors (error in value divided by the value itself)
Formula: U = I * R
Error formula: error_in_U / U = error_in_I/I + error_in_R/R
3) How to define additional rules? (powers, etc)
Is this even possible in Mathcad?
Hi
there was a discussion aout this topic not too long ago:
http://communities.ptc.com/message/228086#228086
This might give you some ideas abotu what is possible & definitely what the pit falls can be.
regards
Andy
Rafal Grasman wrote:
Formula: U = I * R
Error formula: error_in_U / U = error_in_I/I + error_in_R/R
Hmmm!? Lets substitute tolerance for error and let R=(10 +/- 2) ohm, I=(2 +/- 1) A. Smallest result for U would be 8 V, largest result is 36 V. So we don' get a symmetric interval around the nominal 20V. According to the rule you provided for multiplication we would add 2/10 + 1/2 = 7/10. So according to this calculation the relative error for U should be 70%. So the lenght of the interval for U (6 to 34) is the same, but the absolute limits aren't.!!??
It is also not said that you just have to consider the minimum and the maximum value of a variable to get minimum and maximum of a calculation. Let x=(5 +/- 2), so we have a range from 3 to 7 (the examples use an unusal big tolerance to better show the point). The calculation we have to do is y=x*(12-x). We get the minimum for x=2 with y=27, but the maximum value is y=36 for x=6, which is neither end of the x-range.
Using you rule you would get that y has a tolerance of 80%, which would be a range for y from 7 to 63 around the nominal 35, while in real we have to expect the range from 27 to 36 for y.
Calculations with tolerances or errors can be very tricky and I think it would not be practical and worth the effort implementing appropriate routines for the most used operations or even functions like I did with +/- in the thread Andy pointed you to.
Considering all those points led me in trying a brute force approach to find the minumum and maximum value of any calculation using values with tolerances http://communities.ptc.com/message/199660#199660. Any variable is represented by a vector with selectable number of elelemnts and then all those values are combinated and the calculation done to find min and max at the end. A calculation which uses 5 variables and if each variable is represented by 100 values within its range has to do the calculation 100^5 times. So the drawback is clearly apparent - calculation time, possibly in prohibiting dimensions.
The simple rules result from "differentiating" the functions, as in:
(except that each term on the RHS needs to be replaced by its absolute value), so they are really only valid for "small" errors (that's why they are "simple" rules!).
In Mathcad therefore, one could calculate the error of any function by simply differentiating it wrt each of its variables and adding the (absolute values of) the resulting terms. For example:
Alan
Thanks - cheers for the explanatons!
Was too much fixated on an exact calculation but I see now see the potential of those approximate error guessing. I see no practical way to automate this, though.
BTW, if I recall it correctly PSPICE is using kind of a Monte Carlo method to get the range of the result if components with tolerances are used.
Werner Exinger wrote:
I see no practical way to automate this, though.
No, but with a complicated function it might be less error prone to use Mathcad in this way.
BTW, if I recall it correctly PSPICE is using kind of a Monte Carlo method to get the range of the result if components with tolerances are used.
This is fine if you know the error distribution types.
If there are "enough" error variables, whatever their individual distributions they will combine to form (approximately) a normal distribution, so you could root sum square the absolute error terms rather than summing them.
Incidentally, the last expression in my example is better as:
since u and at are essentially 100% correlated with respect to errors in t.
Alan
AlanStevens wrote:
Werner Exinger wrote:
I see no practical way to automate this, though.
No, but with a complicated function it might be less error prone to use Mathcad in this way.
Yes, and here is my attempt to automate the procedure. The function has to be (re)written as vector function which may be a problem and be error prone for longer and complicated functions, the function arguments and their relative tolerances have to provided as nested vector. It works pretty well, but I am not able to turn it into a function. Not sure why, but I guess the unusual usage of symbolic evaluation inside a program takes its toll.
EDIT: Replaced the file by a version with a better and much less error prone way to set up the vector function.
An alternative way to derive the simple rules is to calculate U(u1+deltau1,u2+deltau2, etc.) - U(u1, u2, etc.) and ignore terms involving products of the various components of deltau. This suggests a simpler way of generalising the calculation to any function, albeit keeping the higher order error products - see attached.
Alan
Thats really a very practical, straight foreward and simple approach. As its an error estimation valid for only small errors, I guess replacing E <-- E+ |f(v+dV)-f(v)| by E <-- E + max(|f(v+dV)-f(v)|, |f(v-dV)-f(v)) won't make anything significantly better.