Approximating y = sin x (0 to 90 degrees,
0 to pi/2 radians)
Calculation
I used the HP
Prime to fit polynomials to data by using the vandermonde
and LSQ commands.
vandermonde(vector): creates the matrix
consisting of rows [ 1, (n_i), (n_i)^2, (n_i)^3, …, (n_i)^(n1) ] where the
vector has n elements for each i.
Available from the MathMatrixCreate submenu.
LSQ(X,
y): returns the coefficients [ [a_0],
[a_1], [a_2], … , [a_n] ], the minimum norm least squares vector from the
system X*a=y. In this case, the vector a can also be estimated by the operation (X^T X)^1 X^T y. Available from the
MathMatrixFactorize submenu.
Case 1:
Four Points of Data
Fit cubic polynomial
to the following data. Remember we are working
with the range of 0° ≤ x ≤ 90° or 0 ≤ x ≤ Ï€/2 radians
X

sin(x)

0°

0

30°

1/2 = 0.5

60°

√3/2 ≈ 0.866025403785

90°

1

Example 1: Full precision approximation
y =
1.78098409219E2 x – 1.99435471445E5 x^2 – 6.05408712068E7 x^3
Note: En
stands for 10^(n).
Absolute
maximum error, data measured in 5° tick marks:
0.002371558429
Absolute
maximum error, data measured in 1° tick marks:
0.002392465593
Example 2: If we round all coefficients to six digits,
we get:
y = 0.017810 x –
0.000020 x^2 – 0.000001 x^3
Absolute
maximum error, data measured in 5° tick marks:
0.2881
In comparison
between Example 1 and Example 2, keeping the decimal places makes a big
difference.
Example 3: Let’s see if we do better with using radians
instead of degrees.
X

sin(x)

0

0

Ï€/6

1/2 = 0.5

Ï€/3

√3/2 ≈ 0.866025403785

Ï€/2

1

y =
1.02042871863 x – 0.065470803224 x^2 – 0.113871899065 x^3
Maximum absolute
error, data measured in Ï€/36 radian tick marks: 0.002371558428
Maximum
absolute error, data measured in Ï€/180 radian tick marks: 0.002392465661
The maximum
error in Example 3 matched Example 1.
Example 4: Round the coefficients to six digits:
y = 1.020429 x –
0.065471 x^2 – 0.113872 x^3
Maximum
absolute error, data measured in Ï€/36 radian tick marks: 0.002371292924
(2 decimal
places)
The difference between
Example 2 and Example 4 is that less information is “lost” when rounding the
coefficients to a set amount of digits, in this case, 6.
Case 2: Seven Points of Data
x (degrees)

x (radians)

sin(x)

0°

0

0

15°

Ï€/12

(√6  √2)/4 ≈
0.258819045102

30°

Ï€/6

1/2 = 0.5

45°

Ï€/4

√2/2 ≈ 0.707106781185

60°

Ï€/3

√3/2 ≈ 0.866025403785

75°

5Ï€/12

(√6 + √2)/4 ≈
0.965925826288

90°

Ï€/2

1

Example 5: Full Precision – Degrees
y =
1.74539026131E2 x – 1.00636910048E7 x^2 – 8.79821584089E7 x^3 – 1.93973162632E10
x^4 + 1.66950110845E11 x^5 – 2.72879457224E14 x^6
Absolute
maximum error, data measured in 5° tick marks:
1.2072093E6
(pretty darn
good)
Example 6: Full Precision – Radians
y =
6.98792887569E12 + 1.0000349642 x – 3.30435720904E4 x^2 – 0.165486304503 x^3
– 2.09062241321E3 x^4 + 1.03087220879E2 x^5
 9.65423458482E4 x^6
Maximum
absolute error, data measured in Ï€/36 radian tick marks: 0.00049429473
(3 decimal
places)
I think the
degrees approximation wins. But what if
we round the radians version (Example 6) to 6 decimal places?
Example 7: 6 Decimal Places – Radians
y = 1.000035 x –
0.00033 x^2 – 0.165486 x^3 – 0.002091 x^4 + 0.010309 x^5 – 0.000965 x^6
Maximum
absolute error, data measured in Ï€/36 radian tick marks: 9.03153E6
Interesting result
here, and a nice one at that!
Eddie
This blog is property
of Edward Shore, 2017