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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Be careful absolute value function suffer from overflow and underflow for vectors

ifomenko
15-Moonstone

Be careful absolute value function suffer from overflow and underflow for vectors

norm suffer from overflow and underflow.png

6 REPLIES 6

Interesting results in Prime 4.0 Express

FredKohlhepp_0-1603977054045.png

 

Interesting, yes. I can understand the "Infinity" part (which is better than MC15's 0) as it may be the result of calculating the v^T*v first, which exceeds the IEEE limit, and the root of "infinity" is "infinity" again. But I am confused about the doubled minus sign in the exponent in front of the 2^31 (the largest 32 bit integer is 2^31-1, the most small is -2^31).

So, a bug?

 

Is the other way described a better norm function?

 

FredKohlhepp_0-1603979883579.png

 

Modification to account for negative vector elements:

FredKohlhepp_0-1603979502178.png

Same results

Your infinite norm yields wrong results for "normal" vectors which ifomenkos "infitite norm" does not, as it only triggers if the calculated absolute value of the vector is smaller (0 in case of MC15) as a single vector element.

Personally I don't like those workarounds where the norm of a vector is approximated by the largest absolute value of a single element. The norm of (10^300, 10^300, 10^300)^T is NOT 10^300, but rather about 1.7*10^300.

We all know about the limitations of the IEEE format so we should accept them and learn to live with them (or use different tools like symbolic math for special problems).

All that MC15 should do is to throw an error and not yield a wrong result. Thats also the reason I like Primes behaviour with the funny "infinte" result  a bit more than Mathcads.

 

Werner_E
25-Diamond I
(To:Werner_E)

If we really need a workaround, here is one that seems to work OK

I used Freds idea to select the largest element, but used "-min" instead of "max" so I could avoid the calls to "reverse". As the function only deals with vectors I used "sort" instead of "csort".

Werner_E_0-1604004926768.png

Werner_E_1-1604004992554.png

 

For Express mx may be a separate function which is called multiple times?

EDIT: I guess this version should work in Express, too:

Werner_E_1-1604003910669.png

EDIT3: Here's the shortest version, which also works in Express:

Werner_E_0-1604005396866.png

 

All those workarounds should work in real Mathcad, too.

 

 

 

 

 

Announcements

Top Tags