cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Different units in a ratio give different values

stephen.bepko
1-Newbie

Different units in a ratio give different values

I've defined a function used in optical diffraction theory. The arguments are either dimensionless or ratios of values. When I use different units (but identical in the numerator or denominator), the results are considerably different over a range. Similarly, if I change the units (from, say, length to weight - but the ratio is the same and of course dimensionless), I get different values still.
21 REPLIES 21

On 4/29/2010 3:30:54 PM, sbepko wrote:
>I've defined a function used
>in optical diffraction theory.
>The arguments are either
>dimensionless or ratios of
>values. When I use different
>units (but identical in the
>numerator or denominator), the
>results are considerably
>different over a range.
>Similarly, if I change the
>units (from, say, length to
>weight - but the ratio is the
>same and of course
>dimensionless), I get
>different values still.


But you're integrating that function over y

TTFN,
Eden

I think your integrals are incorrect, due to numerical problems with the rapidly changing integrand. There is too much structure in the integrals to be real.
__________________
� � � � Tom Gutman

The M11 symbolic solver does crank out a result with imaginary terms.

TTFN,
Eden

On 4/29/2010 3:30:54 PM, sbepko wrote:
>I've defined a function used
>in optical diffraction theory.
>... When I use different
>units (but identical in the
>numerator or denominator), the
>results are considerably
>different over a range.

You're running into a limitation of roundoff errors for numerical results calculated with very different number values.

To minimize the problem, bundle your calculation expressions into unitless groups. By all means use units, but make sure that numerical expressions are written in a way that natural cancellation of units can occur where possible.

- Guy

Thanks for all the advice, but it's still not clear to me what's happening here. The integrals are correct in form, I'm positive of that.

How a pure math algorithm detects a difference between meters (only length units make physical sense in the real world situation that my function models) and grams is beyond me, when the units are in a ratio expression and (should) completely cancel out (m/km = g/kg = 10^-3, last time I looked)

Even when the units are the same flavor, I get a difference. Why a ratio of meters to kilometers should calculate differently than a ratio of micron to millimeters is 'disquieting'. Sure, the function that is being integrated are rapidly changing, but so what?

Just remember the immortal words of my former boss- "Reality pales before the beautiful truths to be found within my computer..."

My question boils down to "which answer should I believe"? I'm tempted to think that when I mentally cancel the units out and never enter them in the formula, the answer is good.

As already stated by Eden, you are integrating over y. You have changed the variable name to z, but you are actually integrating over y. For example, the units of y/x may cancel when the units of y and x are the same, but the units of the integral of y/x w.r.t. y do not.

Richard

Don't believe any of them. Your intergrals are mathematically correct, but numerically unstable. I wouldn't trust any of them.
__________________
� � � � Tom Gutman

On 5/5/2010 11:26:22 PM, sbepko wrote:
>Thanks for all the advice, but it's still not clear to me what's happening here. The integrals are correct in form, I'm positive of that.

What happen here is that you don't have an integral. What you write is a calling to a procedure that try to numerically evaluate an integral but the square of the quotient sin(a*z)/sin(b*z) (this is the form of the integrand) make the algorithms that you're calling unstables and unusables.

What you need is an other numerical algorithm to call and the say that you're writing the integral of the function.

Also the concept of small interval for y maybe isn't the same for the integral than for the humans, I see your range for theta very large and I guess that the integral see 96+-10% as a large interval.

Regards. Alvaro.

On 5/5/2010 11:26:22 PM, sbepko wrote:
"Sure, the function that is being integrated are rapidly changing, but so what ?"
_______________________________

There is no "but so what" about numerical integrators. Depending upon the integrand and the integrator, the result is in the range of � 0 error and � infinite error, that can't be appreciated by inspection. Often you will get a good result from "Quadrature". Pass the function as an image, if not too complicated, will try Mathematica with more options than Mathcad.

Consider that simple example



In the attached which is an augmented version of Abramowitz & Stegun, don't drop dead at the last remark, it does not comes out of unknown ... a copy of F.B. Hildebrand . The first Legendre example is just an example, I won't swear on that one. I don't understand what you are talking about the unit, maybe you are saying that if the numerical does not go, it does not entrain the unit system , that makes sense. As it looks, you had no answer yet ?

jmG

In my opinion (and I'm just a physicist, not a math major) the use of units should be independent of the functional form or the numerical method of integration. Simply adding identical units in the numerator and denominator of the function to be integrated changes the value of the integral. In the real world, the units should simply cancel each other out.

Not only that, but changing the flavor of the units (i.e changing from, say, length units to mass units) in the numerator and denominator ALSO changes the value. Make the units, say, kilometers, then change them both to kilograms- the integral evaluates differently.

Does MathCad change the integration algorithm based on the type of units used ?? That would be special... Some programmer would have to go to a lot of trouble for that implementation.

Remember - the units are IDENTICAL in the numerator and denominator, resulting in a dimensionless function !

The ONLY reason I can think of is that, like matrices in MathCad, units are verboten when doing integrals. In matrices, MathCad tells you that with an error splash screen. With integrals, it lets you go blindly forward with a potentially incorrect result. That (lack of error annunciation) to me is a bug, but I'll defer to any higher authority.

The units have nothing to do with it. When you change units you change the values of y. Yes, in the integrand that cancels. But y is the variable of integration, and the range of y there affects the numeric algorithms. Your integrand just varies to quickly for the numeric intgration algorithms to work well, or consistently.
__________________
� � � � Tom Gutman

On 5/6/2010 12:01:33 PM, sbepko wrote:

>The ONLY reason I can think of
>is that, like matrices in
>MathCad, units are verboten
>when doing integrals. In
>matrices, MathCad tells you
>that with an error splash
>screen.

Units aren't verboten in either matrices (although there are restrictions on what you can do with them) or integrals.

Numerical algorithms are not perfect. You are mentally doing a symbolic operation by canceling the units, and then concluding that the ratio is unchanged. Mathcad is not doing that. It is multiplying the numerator and denominator terms by the unit, and then dividing the two results. Due to numerical roundoff that is not the same as dividing the numerator by the denominator.

Richard

OK, I concede. It does appear that MathCad handles things differently in integrals with units than my mind does ;o)

I'm going to trudge on with my original worksheet and assume that if I make everything dimensionless (including the integral limits) than my answer has a finite probability of reflecting reality. To be honest, the results (in my original worksheet) are "close enough for government work" that I've proven what I want to prove (the absolute values of the result are not critical to my conclusions).

Thanks for everyone's input.

"close enough for government work"
__________________________________

You mean :

Close enough where "public dependent safety" is in cause. There are lot more readers than Mathcad 14 users, that's why my suggestion for your integral as an image to capture a wider audience. You mentioned "higher authority", it might just be an external consulting firm, maybe using Mathcad with more veridique results ?

jmG

>>I'm going to trudge on with my original worksheet and assume that if I make everything dimensionless (including the integral limits) than my answer has a finite probability of reflecting reality.<<

Making the numbers dimensionless does not eliminate the problem. You still have to choose a scale (and your choice of units implicitly defined a scale), and some scales may work better than others. But as has been pointed out, your integrand varies too rapidly for the normal numeric integration routines to be reliable.

BTW, part of the issue is that while you canceled the units in the integrand, yielding a dimensionless integrand, that does not result in a dimensionless integral, which will have the units of the variable of integration.
__________________
� � � � Tom Gutman

Actually I'm starting to doubt that this monster of function have a convergent (uniform) integral, nor Cauchy integral too.

Sure that it is not cos in the denominator -which is stable in (-0.5 pi, 0.5 pi)?

I can't figure why a stable phisical process operates at this degree of numerical unstability.

Regards. Alvaro.

On 5/7/2010 4:36:28 AM, adiaz wrote:
>Actually I'm starting to doubt
>that this monster of function
>have a convergent (uniform)
>integral, nor Cauchy integral
>too.
>
>Sure that it is not cos in the
>denominator -which is stable
>in (-0.5 pi, 0.5 pi)?
>
>I can't figure why a stable
>phisical process operates at
>this degree of numerical
>unstability.
>
>Regards. Alvaro.
_____________________________

Integration is a mathematical conjecture, that may have no solution and that often requires a closer look. As I wrote that the result may be exact or infinitely wrong, here is an example that I'm sure you will appreciate.
Two very good references: Mathematica and Maple.
" Integrate uses about 500 pages of Mathematica code and 600 pages of C code."
This invisible integral may have suffered from "miscarriage in construction".



jmG




"...I'll defer to any higher authority."
____________________________

Which in that case the higher authority is:
1. Discretized the function,
2. Run the finite differences cumulative integral

Alternately:
1. Run on DOS or else unitless software
2. Proceed to advanced error tracking like suggested.
3. Make sure that IF "Units match" they are coherent.



Your last chance after the collabs ==> PTC

jmG

The function f(x) listed here will fail if it is evaluated for ANY unit because the second term has no units. (The third term by itself does not have consistent units.) The integral plays no part in the error, it's just the first place the error is encountered.


Fred Kohlhepp
fkohlhepp@sikorsky.com

Well, all is right with the world again. Although I never contacted PTC as to what the fundamental reason was, the solution was simple (and it was hinted at by several responders): Take the "normalization factor" 1/2ydy and put it INSIDE the integral. That makes the integrand dimensionless, and the choice of units doesn't matter. MathCad is happy, I'm happy.
Top Tags