Top Banner
In[2397]:= Needs@"FunctionApproximations`"D In[2398]:= Plot@ArcCos@xD, 8x, - 1, + 1 <, PlotRange 80, p<D Plot@ArcSin@xD, 8x, - 1, + 1 <, PlotRange 8-p 2, p 2<D Plot@ArcTan@xD, 8x, - 10, + 10 <, PlotRange 8-p 2, p 2<D Out[2398]= -1.0 -0.5 0.0 0.5 1.0 0.5 1.0 1.5 2.0 2.5 3.0 Out[2399]= -1.0 -0.5 0.5 1.0 -1.5 -1.0 -0.5 0.5 1.0 1.5 Out[2400]= -10 -5 5 10 -1.5 -1.0 -0.5 0.5 1.0 1.5
9

In[2397]:= Needs FunctionApproximations`D€¦ · In[2401]:= Plot@Sqrt@1-xD, 8x, -1, +1

Oct 30, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: In[2397]:= Needs FunctionApproximations`D€¦ · In[2401]:= Plot@Sqrt@1-xD, 8x, -1, +1

In[2397]:= Needs@"FunctionApproximations`"D

In[2398]:= Plot@ArcCos@xD, 8x, −1, +1 <, PlotRange → 80, π<DPlot@ArcSin@xD, 8x, −1, +1 <, PlotRange → 8−π ê 2, π ê 2<DPlot@ArcTan@xD, 8x, −10, +10 <, PlotRange → 8−π ê 2, π ê 2<D

Out[2398]=

-1.0 -0.5 0.0 0.5 1.0

0.5

1.0

1.5

2.0

2.5

3.0

Out[2399]=

-1.0 -0.5 0.5 1.0

-1.5

-1.0

-0.5

0.5

1.0

1.5

Out[2400]=

-10 -5 5 10

-1.5

-1.0

-0.5

0.5

1.0

1.5

Page 2: In[2397]:= Needs FunctionApproximations`D€¦ · In[2401]:= Plot@Sqrt@1-xD, 8x, -1, +1

In[2401]:=

Plot@Sqrt@1 − xD, 8x, −1, +1 <, PlotRange → 80, π<D

Out[2401]=

-1.0 -0.5 0.0 0.5 1.0

0.5

1.0

1.5

2.0

2.5

3.0

In[2402]:= H∗ ArcCos minimax approximation ∗LH∗ Range can't be @0−1D because of singularity ∗LH∗ Polynomial Minimax for degree 1 ∗LH∗ acosApproxPositiveRelative@x_D=Sqrt@1−xD∗

MiniMaxApproximation@ArcCos@xDêSqrt@1−xD,8x,80,0.99999<,1,0<D@@2,1DD ∗LH∗ acosApproxPositiveAbsolute@x_D=Sqrt@1−xD∗GeneralMiniMaxApproximation@

8t, ArcCos@tDêSqrt@1−tD,1<,8t,80, 0.713<,1,0<,xD@@2,1DD ∗L

H∗ Polynomial Minimax for degree 2 ∗LH∗ acosApproxPositiveRelative@x_D=Sqrt@1−xD∗

MiniMaxApproximation@ArcCos@xDêSqrt@1−xD,8x,80,0.99999<,2,0<D@@2,1DD ∗LH∗ acosApproxPositiveAbsolute@x_D=Sqrt@1−xD∗GeneralMiniMaxApproximation@

8t, ArcCos@tDêSqrt@1−tD,1<,8t,80, 0.822<,2,0<,xD@@2,1DD ∗L

H∗ Polynomial Minimax for degree 3 ∗LacosApproxPositiveRelative@x_D = Sqrt@1 − xD ∗

MiniMaxApproximation@ArcCos@xD ê Sqrt@1 − xD, 8x, 80, 0.99999<, 3, 0<D@@2, 1DDacosApproxPositiveAbsolute@x_D = Sqrt@1 − xD ∗ GeneralMiniMaxApproximation@

8t, ArcCos@tD ê Sqrt@1 − tD, 1<, 8t, 80, 0.8776<, 3, 0<, xD@@2, 1DD

H∗ Polynomial Minimax for degree 3 with

correct boundary at 0 and 1 for the result ∗LH∗ acosApproxPositiveRelative@x_D=Sqrt@1−xD∗

[email protected] + xHSqrt@2D − 1.570796L+ x∗Hx−1L ∗ MiniMaxApproximation@H−1.570796 −x∗HSqrt@2D − 1.570796L+ArcCos@xDêSqrt@1−xDLêHx∗Hx−1LL,

8x,80.1989,0.7636<,1,0<D@@2,1DD D ∗LH∗ acosApproxPositiveAbsolute@x_D=Sqrt@1−xD∗Expand@

1.570796 + xHSqrt@2D − 1.570796L+ x∗Hx−1L ∗ GeneralMiniMaxApproximation@8t, H−1.570796 −t∗HSqrt@2D − 1.570796L+ArcCos@tDêSqrt@1−tDLêHt∗Ht−1LL,

1<,8t,80.158,0.694<,1,0<, xD@@2,1DD D ∗L

H∗ Polynomial Minimax for degree 1 with David Eberly coefficient get from

http:êêwww.geometrictools.comêGTEngineêIncludeêGteConstants.h. Minimize

for relative but store in acosApproxPositiveAbsolute for comparison. ∗LH∗ acosApproxPositiveAbsolute@x_D=

1−x H1.5707963267948966−0.15658276442180141xL ∗L

2 GPUInverseTrigoForGCN_v3.nb

Page 3: In[2397]:= Needs FunctionApproximations`D€¦ · In[2401]:= Plot@Sqrt@1-xD, 8x, -1, +1

In[2402]:=

H∗ Polynomial Minimax for degree 2 with David Eberly coefficient get from

http:êêwww.geometrictools.comêGTEngineêIncludeêGteConstants.h. ∗LH∗ acosApproxPositiveAbsolute@x_D=

1−x I1.5707963267948966−0.20347053865798365x + 0.046887774236182234x2M ∗LH∗ Polynomial Minimax for degree 3 with David Eberly coefficient get from

http:êêwww.geometrictools.comêGTEngineêIncludeêGteConstants.h. ∗LH∗ acosApproxPositiveAbsolute@x_D=

1−x I1.5707963267948966−0.21253291899190285x+

0.074773789639484223 x2−0.018823635069382449 x3M ∗L

H∗ Simple test to show the Minimax approximation

with a constant term of PIê2 imposed for the result. ∗LH∗ acosApproxPositiveAbsolute@x_D=

Sqrt@1−xD∗H1.570796+x∗MiniMaxApproximation@HArcCos@xD−1.570796∗Sqrt@1−xDLêHx∗Sqrt@1−xDL,8x,80.001,0.95<,2,0<D@@2,1DDL ∗L

H∗ Use identity to retrieve whole curve ∗LacosApproxRelative@x_D = If@x >= 0,

acosApproxPositiveRelative@xD, π − acosApproxPositiveRelative@Abs@xDDD;

acosApproxAbsolute@x_D = If@x >= 0, acosApproxPositiveAbsolute@xD,

π − acosApproxPositiveAbsolute@Abs@xDDD;

H∗ Horner form for conversion to AMD GCN ∗LSqrt@1 − xD ∗ HornerForm@acosApproxPositiveRelative@xD ê Sqrt@1 − xDD êê

TraditionalForm;

Sqrt@1 − xD ∗ HornerForm@acosApproxPositiveAbsolute@xD ê Sqrt@1 − xDD êêTraditionalForm;

H∗ Compare approx ∗LPlot@8ArcCos@xD, acosApproxRelative@xD, acosApproxAbsolute@xD<,

8x, −1, 1<, PlotRange → 80, π<D;

Plot@8ArcCos@xD, acosApproxRelative@xD<, 8x, −1, 1<, PlotRange → 80, π<D;

H∗ Absolute error ê Relative error ∗LGraphicsRow@8Plot@8Abs@ArcCos@xD − acosApproxRelative@xDD,

Abs@ArcCos@xD − acosApproxAbsolute@xDD<, 8x, 0, 1<D,

Plot@8Abs@1 − acosApproxRelative@xD ê ArcCos@xD D,

Abs@1 − acosApproxAbsolute@xD ê ArcCos@xD D<,

8x, 0, 1<D<, ImageSize −> 8800, 300<DGraphicsRow@8Plot@8Abs@ArcCos@xD − acosApproxRelative@xDD<, 8x, 0, 1<D,

Plot@8Abs@1 − acosApproxRelative@xD ê ArcCos@xD D<, 8x, 0, 1<D<,

ImageSize −> 8800, 300<D;

GraphicsRow@8Plot@8Abs@ArcCos@xD − acosApproxAbsolute@xDD<, 8x, 0, 1<D,

Plot@8Abs@1 − acosApproxAbsolute@xD ê ArcCos@xD D<, 8x, 0, 1<D<,

ImageSize −> 8800, 300<D;

H∗ Find the maximun relativeêabsolute error∗LH∗ This is tricky because we have a lot of local maximun,

so we can't use the FindMaximum call ∗LH∗ Simply brute force looping to find the maximun ∗L8maxAbsoluteErrorRelative = 0.0;

maxAbsoluteErrorAbsolute = 0.0;

maxRelativeErrorRelative = 0.0;

maxRelativeErrorAbsolute = 0.0;

For @ incr = 0.0, incr ≤ H1.0 − 0.0001L, incr += 0.0001 ;

valAbsoluteErrorRelative = Abs@ArcCos@incrD − acosApproxRelative@incrDD;

;

GPUInverseTrigoForGCN_v3.nb 3

Page 4: In[2397]:= Needs FunctionApproximations`D€¦ · In[2401]:= Plot@Sqrt@1-xD, 8x, -1, +1

In[2402]:=

valAbsoluteErrorAbsolute = Abs@ArcCos@incrD − acosApproxAbsolute@incrDD;

valRelativeErrorRelative = Abs@1 − acosApproxRelative@incrD ê ArcCos@incrD D;

valRelativeErrorAbsolute = Abs@1 − acosApproxAbsolute@incrD ê ArcCos@incrD D;

If@valAbsoluteErrorRelative >= maxAbsoluteErrorRelative,

maxAbsoluteErrorRelative = valAbsoluteErrorRelative, 0D;

If@valAbsoluteErrorAbsolute >= maxAbsoluteErrorAbsolute,

maxAbsoluteErrorAbsolute = valAbsoluteErrorAbsolute, 0D;

If@valRelativeErrorRelative >= maxRelativeErrorRelative,

maxRelativeErrorRelative = valRelativeErrorRelative, 0D;

If@valRelativeErrorAbsolute >= maxRelativeErrorAbsolute,

maxRelativeErrorAbsolute = valRelativeErrorAbsolute, 0DD;

8ScientificForm@maxAbsoluteErrorRelativeD,

ScientificForm@maxAbsoluteErrorAbsoluteD<,

8ScientificForm@maxRelativeErrorRelativeD,

ScientificForm@maxRelativeErrorAbsoluteD<<

Out[2402]= 1 − x I1.57073 − 0.212053 x + 0.0740935 x2

− 0.0186166 x3M

Out[2403]= 1 − x I1.57075 − 0.21271 x + 0.0764532 x2

− 0.0206453 x3M

Out[2410]=

0.2 0.4 0.6 0.8 1.0

0.00001

0.00002

0.00003

0.00004

0.00005

0.00006

0.00007

0.2 0.4

0.00002

0.00004

0.00006

0.00008

Out[2413]= 997.06471 × 10−5

, 4.55365 × 10−5=, 94.5153 × 10

−5, 2.57813 × 10

−4==

In[2414]:= H∗ ArcSin minimax approximation ∗LH∗ Range can't be @0−1D because of singularity ∗LasinApproxPositiveRelative@x_D =

Hπ ê 2L − Sqrt@1 − xD ∗ MiniMaxApproximation@HHπ ê 2L − ArcSin@xD L ê Sqrt@1 − xD,

8x, 80, 0.99999<, 3, 0<D@@2, 1DDasinApproxPositiveAbsolute@x_D = Hπ ê 2L − Sqrt@1 − xD ∗ GeneralMiniMaxApproximation@

8t, HHπ ê 2L − ArcSin@tD L ê Sqrt@1 − tD, 1<, 8t, 80, 0.8776<, 3, 0<, xD@@2, 1DD

H∗ Polynomial Minimax for degree 3 with David Eberly coefficient get from

http:êêwww.geometrictools.comêGTEngineêIncludeêGteConstants.h. Minimize

for relative but store in asinApproxPositiveAbsolute for comparison. ∗LH∗ asinApproxPositiveAbsolute@x_D=

4 GPUInverseTrigoForGCN_v3.nb

Page 5: In[2397]:= Needs FunctionApproximations`D€¦ · In[2401]:= Plot@Sqrt@1-xD, 8x, -1, +1

In[2414]:=

Hπê2L− 1−x I1.5707963267948966−0.21253291899190285x+

0.074773789639484223 x2−0.018823635069382449 x3M ∗L

H∗ Use identity to retrieve whole curve ∗LasinApproxRelative@x_D = If@x >= 0,

asinApproxPositiveRelative@xD, − asinApproxPositiveRelative@Abs@xDDD;

asinApproxAbsolute@x_D = If@x >= 0, asinApproxPositiveAbsolute@xD,

− asinApproxPositiveAbsolute@Abs@xDDD;

H∗ Horner form for conversion to AMD GCN ∗LHπ ê 2L − Sqrt@1 − xD ∗ HornerForm@

HasinApproxPositiveRelative@xD − Hπ ê 2LL ê Sqrt@1 − xDD êê TraditionalForm;

Hπ ê 2L − Sqrt@1 − xD ∗ HornerForm@HasinApproxPositiveAbsolute@xD − Hπ ê 2LL êSqrt@1 − xDD êê TraditionalForm;

H∗ Compare approx ∗LPlot@8ArcSin@xD, asinApproxRelative@xD, asinApproxAbsolute@xD<,

8x, −1, 1<, PlotRange → 8−π ê 2, π ê 2<D;

Plot@8ArcSin@xD, asinApproxRelative@xD<,

8x, −1, 1<, PlotRange → 8−π ê 2, π ê 2<D;

H∗ Absolute error ê Relative error ∗LGraphicsRow@8Plot@8Abs@ArcSin@xD − asinApproxRelative@xDD,

Abs@ArcSin@xD − asinApproxAbsolute@xDD<, 8x, 0, 1<D,

Plot@8Abs@1 − asinApproxRelative@xD ê ArcSin@xD D,

Abs@1 − asinApproxAbsolute@xD ê ArcSin@xD D<,

8x, 0, 1<D<, ImageSize −> 8800, 300<DGraphicsRow@8Plot@8Abs@ArcSin@xD − asinApproxRelative@xDD<, 8x, 0, 1<D,

Plot@8Abs@1 − asinApproxRelative@xD ê ArcSin@xD D<, 8x, 0, 1<D<,

ImageSize −> 8800, 300<D;

GraphicsRow@8Plot@8Abs@ArcSin@xD − asinApproxAbsolute@xDD<, 8x, 0, 1<D,

Plot@8Abs@1 − asinApproxAbsolute@xD ê ArcSin@xD D<, 8x, 0, 1<D<,

ImageSize −> 8800, 300<D;

H∗ Find the maximun aboslute error∗LH∗ This is tricky because we have a lot of local maximun,

so we can't use the FindMaximum call ∗LH∗ Simply brute force looping to find the maximun ∗L8maxAbsoluteErrorRelative = 0.0;

maxAbsoluteErrorAbsolute = 0.0;

maxRelativeErrorRelative = 0.0;

maxRelativeErrorAbsolute = 0.0;

For @ incr = 0.0, incr ≤ H1.0 − 0.0001L, incr += 0.0001 ;

valAbsoluteErrorRelative = Abs@ArcSin@incrD − asinApproxRelative@incrDD;

valAbsoluteErrorAbsolute = Abs@ArcSin@incrD − asinApproxAbsolute@incrDD;

valRelativeErrorRelative = Abs@1 − asinApproxRelative@incrD ê ArcSin@incrD D;

valRelativeErrorAbsolute = Abs@1 − asinApproxAbsolute@incrD ê ArcSin@incrD D;

If@valAbsoluteErrorRelative >= maxAbsoluteErrorRelative,

maxAbsoluteErrorRelative = valAbsoluteErrorRelative, 0D;

If@valAbsoluteErrorAbsolute >= maxAbsoluteErrorAbsolute,

maxAbsoluteErrorAbsolute = valAbsoluteErrorAbsolute, 0D;

If@valRelativeErrorRelative >= maxRelativeErrorRelative,

maxRelativeErrorRelative = valRelativeErrorRelative, 0D;

If@valRelativeErrorAbsolute >= maxRelativeErrorAbsolute,

maxRelativeErrorAbsolute = valRelativeErrorAbsolute, 0DD;

GPUInverseTrigoForGCN_v3.nb 5

Page 6: In[2397]:= Needs FunctionApproximations`D€¦ · In[2401]:= Plot@Sqrt@1-xD, 8x, -1, +1

In[2414]:=

8ScientificForm@maxAbsoluteErrorRelativeD,

ScientificForm@maxAbsoluteErrorAbsoluteD<,

8ScientificForm@maxRelativeErrorRelativeD,

ScientificForm@maxRelativeErrorAbsoluteD<<

Out[2414]=

π

2

− 1 − x I1.57073 − 0.212053 x + 0.0740935 x2

− 0.0186166 x3M

Out[2415]=

π

2

− 1 − x I1.57075 − 0.21271 x + 0.0764532 x2

− 0.0206453 x3M

Out[2422]=

0.2 0.4 0.6 0.8 1.0

0.00001

0.00002

0.00003

0.00004

0.00005

0.00006

0.00007

0.2 0.4

0.0001

0.0002

0.0003

0.0004

Out[2425]= 997.06471 × 10−5

, 4.55365 × 10−5=, 97.06471 × 10

−1, 4.55365 × 10

−1==

In[2426]:= H∗ Atan minimax approximation ∗LH∗ Range can't be @0−1D because of singularity ∗L

H∗ polynomial −

uncomment the line below "inputExponent" when using polynomial ∗LH∗ inputExponent = 1;∗LH∗ Polynomial degree 2 ∗LH∗atanApproxPositive01Relative@x_D=

x∗MiniMaxApproximation@ArcTan@xDêx ,8x,80.0001,1<,1,0<D@@2,1DDatanApproxPositive01Absolute@x_D= x∗GeneralMiniMaxApproximation@

8t, ArcTan@tDêt , 1<,8t,80.33,1<,1,0<, xD@@2,1DD∗LH∗ Polynomial degree 3 ∗LH∗ atanApproxPositive01Relative@x_D=

x∗MiniMaxApproximation@ArcTan@xDêx ,8x,80.0001,1<,2,0<D@@2,1DDatanApproxPositive01Absolute@x_D= x∗GeneralMiniMaxApproximation@

8t, ArcTan@tDêt , 1<,8t,80.278,1<,2,0<, xD@@2,1DD ∗L

H∗ polynomial −

uncomment the line below "inputExponent" when using odd polynomial ∗LinputExponent = 2;

H∗ odd Polynomial degree 3 ∗LatanApproxPositive01Relative@x_D = Sqrt@xD ∗

MiniMaxApproximation@ArcTan@Sqrt@xDD ê Sqrt@xD , 8x, 80.0001, 1<, 1, 0<D@@2, 1DDatanApproxPositive01Absolute@x_D = Sqrt@xD ∗ GeneralMiniMaxApproximation@

D@ D

6 GPUInverseTrigoForGCN_v3.nb

Page 7: In[2397]:= Needs FunctionApproximations`D€¦ · In[2401]:= Plot@Sqrt@1-xD, 8x, -1, +1

In[2426]:=

8t, ArcTan@Sqrt@tDD ê Sqrt@tD , 1<, 8t, 80.234, 1<, 1, 0<, xD@@2, 1DDH∗ odd Polynomial degree 5 ∗LH∗ atanApproxPositive01Relative@x_D=Sqrt@xD∗

MiniMaxApproximation@ArcTan@Sqrt@xDDêSqrt@xD ,8x,80.0001,1<,2,0<D@@2,1DD ∗LH∗ atanApproxPositive01Absolute@x_D= Sqrt@xD∗GeneralMiniMaxApproximation@

8t, ArcTan@Sqrt@tDDêSqrt@tD , 1<,8t,80.148,1<,2,0<, xD@@2,1DD∗L

H∗ polynomial −

uncomment the line below "inputExponent" when using odd polynomial ∗LH∗ inputExponent = 1;∗LH∗ odd Polynomial 3 degree with David Eberly coefficient get from http:êê

www.geometrictools.comêGTEngineêIncludeêGteConstants.h. ∗LH∗ atanApproxPositive01Relative@x_D=Hx−0.21460183660255172x^3L ∗LH∗ Same for degree 5 with David Eberly coefficient get from http:êê

www.geometrictools.comêGTEngineêIncludeêGteConstants.h. ∗LH∗ atanApproxPositive01Relative@x_D=

Hx−0.30189478312144946x^3 + 0.087292946518897740∗x^5L ∗L

H∗ All previous polynomial use 2 following functions to undo the range

reduction − need to be commented if odd polynomials alternate are use ∗LatanApproxPositiveRelative@x_D =

If@x ≤ 1, atanApproxPositive01Relative@x^inputExponentD,

Hπ ê 2L − atanApproxPositive01Relative@H1 ê xL^inputExponentDD;

atanApproxPositiveAbsolute@x_D =

If@x ≤ 1, atanApproxPositive01Absolute@x^inputExponentD,

Hπ ê 2L − atanApproxPositive01Absolute@H1 ê xL^inputExponentDD;

H∗ polynomial alternate−

uncomment the line below "inputExponent" when using odd polynomial ∗LH∗inputExponent = 2;∗LH∗ odd Polynomial degree alternate 3 ∗LH∗ atanApproxPositive01Relative@x_D=

MiniMaxApproximation@ArcTan@Sqrt@xDDêSqrt@xD ,8x,80.0001,1<,1,0<D@@2,1DD ∗LH∗ atanApproxPositive01Absolute@x_D= GeneralMiniMaxApproximation@

8t, ArcTan@Sqrt@tDDêSqrt@tD , 1<,8t,80.234,1<,1,0<, xD@@2,1DD ∗LH∗ odd Polynomial degree alternate 5 ∗LH∗ atanApproxPositive01Relative@x_D=

MiniMaxApproximation@ArcTan@Sqrt@xDDêSqrt@xD ,8x,80.0001,1<,2,0<D@@2,1DD∗LH∗atanApproxPositive01Absolute@x_D= GeneralMiniMaxApproximation@

8t, ArcTan@Sqrt@tDDêSqrt@tD , 1<,8t,80.148,1<,2,0<, xD@@2,1DD∗L

H∗ Alternate polynomial use 2

following functions to undo the range reduction −

need to be commented if other polynomials are use. π ê 4 = 0.785398 ∗LH∗ atanApproxPositiveRelative@x_D=0.785398 +

HHx−1LêHx+1LL∗atanApproxPositive01Absolute@HHx−1LêHx+1LL^inputExponentD;

atanApproxPositiveAbsolute@x_D=0.785398 +

HHx−1LêHx+1LL∗atanApproxPositive01Absolute@HHx−1LêHx+1LL^inputExponentD; ∗L

H∗ Use identity to retrieve whole curve∗LatanApproxRelative@x_D = If@x >= 0,

atanApproxPositiveRelative@xD, −atanApproxPositiveRelative@Abs@xDDD;

atanApproxAbsolute@x_D = If@x >= 0, atanApproxPositiveAbsolute@xD,

D;

GPUInverseTrigoForGCN_v3.nb 7

Page 8: In[2397]:= Needs FunctionApproximations`D€¦ · In[2401]:= Plot@Sqrt@1-xD, 8x, -1, +1

In[2426]:=

−atanApproxPositiveAbsolute@Abs@xDDD;

H∗ Horner form for conversion to AMD GCN ∗Lx ∗ HornerForm@Simplify@HatanApproxPositive01Relative@x^inputExponentD L,

x > 0D ê xD êê TraditionalForm;

x ∗ HornerForm@Simplify@HatanApproxPositive01Absolute@x^inputExponentDL,

x > 0D ê xD êê TraditionalForm;

H∗ Compare approx ∗LPlot@8ArcTan@xD, atanApproxRelative@xD, atanApproxAbsolute@xD<,

8x, −30, 30<, PlotRange → 8−π ê 2, π ê 2<D;

Plot@8ArcTan@xD, atanApproxRelative@xD<,

8x, −30, 30<, PlotRange → 8−π ê 2, π ê 2<D;

H∗ Absolute error ê Relative error ∗LGraphicsRow@8Plot@8Abs@ArcTan@xD − atanApproxRelative@xDD,

Abs@ArcTan@xD − atanApproxAbsolute@xDD<, 8x, 0, 1<D,

Plot@8Abs@1 − atanApproxRelative@xD ê ArcTan@xD D,

Abs@1 − atanApproxAbsolute@xD ê ArcTan@xD D<,

8x, 0, 1<D<, ImageSize −> 8800, 300<DGraphicsRow@8Plot@8Abs@ArcTan@xD − atanApproxRelative@xDD<, 8x, 0, 1<D,

Plot@8Abs@1 − atanApproxRelative@xD ê ArcTan@xD D<, 8x, 0, 1<D<,

ImageSize −> 8800, 300<D;

GraphicsRow@8Plot@8Abs@ArcTan@xD − atanApproxAbsolute@xDD<, 8x, 0, 1<D,

Plot@8Abs@1 − atanApproxAbsolute@xD ê ArcTan@xD D<, 8x, 0, 1<D<,

ImageSize −> 8800, 300<D;

H∗ Find the maximun aboslute error∗LH∗ This is tricky because we have a lot of local maximun,

so we can't use the FindMaximum call ∗LH∗ Simply brute force looping to find the maximun ∗L8maxAbsoluteErrorRelative = 0.0;

maxAbsoluteErrorAbsolute = 0.0;

maxRelativeErrorRelative = 0.0;

maxRelativeErrorAbsolute = 0.0;

For @ incr = 0.0, incr ≤ H1.0 − 0.0001L, incr += 0.0001 ;

valAbsoluteErrorRelative = Abs@ArcTan@incrD − atanApproxRelative@incrDD;

valAbsoluteErrorAbsolute = Abs@ArcTan@incrD − atanApproxAbsolute@incrDD;

valRelativeErrorRelative = Abs@1 − atanApproxRelative@incrD ê ArcTan@incrD D;

valRelativeErrorAbsolute = Abs@1 − atanApproxAbsolute@incrD ê ArcTan@incrD D;

If@valAbsoluteErrorRelative >= maxAbsoluteErrorRelative,

maxAbsoluteErrorRelative = valAbsoluteErrorRelative, 0D;

If@valAbsoluteErrorAbsolute >= maxAbsoluteErrorAbsolute,

maxAbsoluteErrorAbsolute = valAbsoluteErrorAbsolute, 0D;

If@valRelativeErrorRelative >= maxRelativeErrorRelative,

maxRelativeErrorRelative = valRelativeErrorRelative, 0D;

If@valRelativeErrorAbsolute >= maxRelativeErrorAbsolute,

maxRelativeErrorAbsolute = valRelativeErrorAbsolute, 0DD;

8ScientificForm@maxAbsoluteErrorRelativeD,

ScientificForm@maxAbsoluteErrorAbsoluteD<,

8ScientificForm@maxRelativeErrorRelativeD,

ScientificForm@maxRelativeErrorAbsoluteD<<

Out[2427]= H0.987305 − 0.211868 xL x

8 GPUInverseTrigoForGCN_v3.nb

Page 9: In[2397]:= Needs FunctionApproximations`D€¦ · In[2401]:= Plot@Sqrt@1-xD, 8x, -1, +1

Out[2428]= H0.970592 − 0.190604 xL x

Out[2437]=

0.2 0.4 0.6 0.8 1.0

0.002

0.004

0.006

0.008

0.010

0.2 0.4

0.005

0.010

0.015

0.020

0.025

0.030

Out[2440]= 999.96164 × 10−3

, 5.4343 × 10−3=, 91.26953 × 10

−2, 2.94077 × 10

−2==

GPUInverseTrigoForGCN_v3.nb 9