fb:porticula NoPaste
t_cst.bas
Uploader: | Volta |
Datum/Zeit: | 30.09.2010 20:40:28 |
'PROGRAM test_cst
' Test of sine, cosine & tangent
' 1. sin(2.x) = 2.sin(x).cos(x)
' 2. cos(2.x) = (cos(x) + sin(x)).(cos(x) - sin(x))
' 3. sec(x)^2 = 1 + tan(x)^2
#Include "quad_1x.bi"
Using quad_precision
#define EPSILON_HALF 2.22044604925031308E-016
Dim As quad x, twox, sine, cosine, tangent, lhs, rhs, diff
Dim As Double r
Dim As Integer i
Screen 0
Width 104,32
Color 15,1
Cls
Randomize 4711
For i = 1 To 10
x.hi=Rnd
r= Rnd
x.hi = (x.hi - 0.5) / r
x.lo = x.hi * EPSILON_HALF
' sin(2.x) = 2.sin(x).cos(x)
twox = 2.0 * x
lhs = Sin(twox)
sine = Sin(x)
cosine = Cos(x)
rhs = sine * cosine
rhs = 2.0 * rhs
diff = lhs - rhs
Print "sin(2x) lhs ="; lhs, " Diff. ="; diff
' cos(2.x) = (cos(x) + sin(x)).(cos(x) - sin(x))
lhs = Cos(twox)
rhs = (cosine + sine) * (cosine - sine)
diff = lhs - rhs
Print "cos(2x) lhs ="; lhs, " Diff. ="; diff
' sec(x)**2 = 1 + tan(x)**2
diff.hi = 1.0
diff.lo = 0.0
lhs = diff / cosine
lhs = lhs * lhs
tangent = Tan(x)
rhs = diff + tangent * tangent
diff = lhs - rhs
Print "sec(x)^2 lhs ="; lhs, " Diff. ="; diff
Next
Sleep