﻿ Handling Higher Math

﻿

JavaScript Editor     JavaScript Debugger

Main Page

## Handling Higher Math

Well, it may have been a mistake taking on that programming job from the astrophysics department. How do you calculate a hyperbolic cosecant anyway? Can Visual Basic do it? Yes, although not directly. The built-in Visual Basic math functions appear in Table 2.8-note that the old VB6 functions like Atn and Abs have been replaced by methods of the System.Math namespace.

Table 2.8: Math methods.

Old

New Visual Basic .NET method

Description

Abs

System.Math.Abs

Yields the absolute value of a given number.

Atn

System.Math.Atan

Yields a Double value containing the angle whose tangent is the given number.

Cos

System.Math.Cos

Yields a Double value containing the cosine of the given angle.

Exp

System.Math.Exp

Yields a Double value containing e (the base of natural logarithms) raised to the given power.

Log

System.Math.Log

Yields a Double value containing the logarithm of a given number.

Round

System.Math.Round

Yields a Double value containing the number nearest the given value.

Sgn

System.Math.Sign

Yields an Integer value indicating the sign of a number.

Sin

System.Math.Sin

Yields a Double value specifying the sine of an angle.

Sqr

System.Math.Sqrt

Yields a Double value specifying the square root of a number.

Tan

System.Math.Tan

Yields a Double value containing the tangent of an angle.

To use these functions without qualification, import the System.Math namespace into your project. Here's an example that uses the Atan method:

```Imports System.Math
Module Module1
Sub Main()
System.Console.WriteLine("Pi =" & 4 * Atan(1))
End Sub
End Module
```

And here's the result:

```Pi =3.14159265358979
Press any key to continue
```

If what you want, like hyperbolic cosecant, is not in Table 2.8, try Table 2.9, which shows you how to calculate other results using the built-in Visual Basic functions. There's enough math power in Table 2.9 to keep most astrophysicists happy.

Table 2.9: Calculated math functions.

Function

Calculate this way

Secant

Sec(X) = 1 / Cos(X)

Cosecant

Cosec(X) = 1 / Sin(X)

Cotangent

Cotan(X) = 1 / Tan(X)

Inverse Sine

Arcsin(X) = Atn(X / Sqr(-X * X + 1))

Inverse Cosine

Arccos(X) = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)

Inverse Secant

Arcsec(X) = Atn(X / Sqr(X * X - 1)) + Sgn((X) - 1) * (2 * Atn(1))

Inverse Cosecant

Arccosec(X) = Atn(X / Sqr(X * X - 1)) + (Sgn(X) - 1) * (2 * Atn(1))

Inverse Cotangent

Arccotan(X) = Atn(X) + 2 * Atn(1)

Hyperbolic Sine

HSin(X) = (Exp(X) - Exp(-X)) / 2

Hyperbolic Cosine

HCos(X) = (Exp(X) + Exp(-X)) / 2

Hyperbolic Tangent

HTan(X) = (Exp(X) - Exp(-X)) / (Exp(X) + Exp(-X))

Hyperbolic Secant

HSec(X) = 2 / (Exp(X) + Exp(-X))

Hyperbolic Cosecant

HCosec(X) = 2 / (Exp(X) - Exp(-X))

Hyperbolic Cotangent

HCotan(X) = (Exp(X) + Exp(-X)) / (Exp(X) - Exp(-X))

Inverse Hyperbolic Sine

HArcsin(X) = Log(X + Sqr(X * X + 1))

Inverse Hyperbolic Cosine

HArccos(X) = Log(X + Sqr(X * X - 1))

Inverse Hyperbolic Tangent

HArctan(X) = Log((1 + X) / (1 - X)) / 2

Inverse Hyperbolic Secant

HArcsec(X) = Log((Sqr(-X * X + 1) + 1) / X)

Inverse Hyperbolic Cosecant

HArccosec(X) = Log((Sgn(X) * Sqr(X * X + 1) + 1) / X)

Inverse Hyperbolic Cotangent

HArccotan(X) = Log((X + 1) / (X - 1)) / 2

Logarithm to base N

LogN(X) = Log(X) / Log(N)

Free JavaScript Editor     JavaScript Editor ﻿