New Version 6.0! |
---|

Try it for free with our fully functional 60-day trial version. |

QuickStart Samples

# Elementary Functions QuickStart Sample (IronPython)

Illustrates how to use additional elementary functions in IronPython.

C# code Visual Basic code F# code Back to QuickStart Samples

import numerics from math import * # We use many classes from the Extreme.Mathematics namespace. from Extreme.Mathematics import * #/ Illustrates the use of the elementary functions implemented #/ by the Elementary class in the Extreme.Mathematics.Curve namespace of #/ the Extreme Optimization Mathematics Library for .NET. # This QuickStart sample deals with elementary # functions, implemented in the Elementary class. # # Elementary functions # # Evaluating Log(1+x) directly causes significant # round-off error when x is close to 0. The # Log1PlusX function allows high precision evaluation # of this expression for values of x close to 0: print "Logarithm of 1+1e-12" print " Math.Log:", log(1+1e-12) print " Log1PlusX:", Elementary.Log1PlusX(1e-12) # In a similar way, Exp(x) - 1 has a variant, # ExpXMinus1, for values of x close to 0: print "Exponential of 1e-12 minus 1." print " Math.Exp:", exp(1e-12) - 1 print " ExpMinus1:", Elementary.ExpMinus1(1e-12) # The hypotenuse of two numbers that are very large # may cause an overflow when not evaluated properly: print "Hypotenuse:" a = 3e200 b = 4e200 print " Simple method: " try: sumOfSquares = a*a + b*b Math.Sqrt(sumOfSquares) except: # (OverflowException) print "Overflow!" print " Elementary.Hypot:", Elementary.Hypot(a, b) # Raising numbers to integer powers is much faster # than raising numbers to real numbers. The # overloaded Pow method implements this: print "2.5^19 =", Elementary.Pow(2.5, 19) # You can raise numbers to negative integer powers # as well: print "2.5^-19 =", Elementary.Pow(2.5,-19)

Copyright Â© 2003-2015, Extreme Optimization. All rights reserved.

*Extreme Optimization,* *Complexity made simple*, *M#*, and *M Sharp* are trademarks of ExoAnalytics Inc.

*Microsoft*, *Visual C#, Visual Basic, Visual Studio*, *Visual Studio.NET*, and the *Optimized for Visual Studio* logo

are registered trademarks of Microsoft Corporation.