The main purpose of this assignment is to emulate the built-in Visual Basic “Math” library
functions/methods. You are required to address only a small subset of these Math methods, namely the
constant e (base of natural logarithms) and a few of the trigonometric functions: sine (sin), cosine (cos),
tangent (tan) and constant π. You clearly need some understanding of these functions, but I will give the
basics which should be sufficient to complete this final assignment. You are not allowed to use the two
constants and these trig functions from “Math” – you can only use the “Math” library functions for error
determination purposes which will be expressed in scientific notation. You may use other Math methods
as needed.
The actual computation of e, π and sine (x is in radians) has to be performed by using the following
infinite series:
= 1 +
1
1!
+
1
2!
+
1
3!
+ ⋯
= 12 1 −
1
3 ∙ 3
+
1
5 ∙ 3. −
1
7 ∙ 30 + ⋯
sin = −
0
3!
+
5
5!
−
6
7!
+ ⋯
Where n! stands for n factorial and n! = n (n-1) (n-2)… For example 5! = 5 * 4 * 3 * 2 * 1 = 120. All
computations have to be done using the “Decimal” data type to achieve higher accuracy. However,
inputs and outputs are of type “Double”.
Hint: Do not compute each term (numerator and denominator) of the above equations from scratch but
base it on the previously computed values. You should stop adding terms when the value of the last
term is less than 1e-17 (beyond VB “double” accuracy). Use your computed value of π when needed for
other computations. All these functions/methods are to be implemented using a VB Class, appropriately
called “MyMath”. Look at the sample code provided below.
The following trigonometric identities should be used to simplify computations (angles are in degrees):
For sin x (using symmetry), in this particular order:
if x > 360 x = x – 360
if x > 270 sin x = -sin(360 – x)
if x > 180 sin x = -sin(x – 180)
if x > 90 x = 180 – x
cos x = sin (x + 90)
tan x = sin x / cos x
The range of angles for all trig methods is from 0 to 360 degrees. Due to above identities, you’ll only
need to make computations for the first quadrant, i.e., 0 – 90 degrees.
For the following five values of x, do not compute sin x as explained above, but use this table (based on
simple geometric properties):