Post Reply 
Bürgi's Kunstweg to Calculate Sines
05-09-2022, 04:55 PM
Post: #4
RE: Bürgi's Kunstweg to Calculate Sines
(05-09-2022 01:48 AM)Albert Chan Wrote:  Asymmetry of matrix, [2,-1] top, [-2,2] bottom , we should match edge cases coefficients.

Another way is to split central difference to 2 steps, forward diff, then backward diff.
Below, 1 ≡ 10°, (0-1) ≡ sin(0°) - sin(10°) = -sin(10°) ≡ -1

Code:
0     F        B F
1   (0-1)   (0-1)-(1-2)
2   (1-2)   (1-2)-(2-3)
3   (2-3)   (2-3)-(3-4)
4   (3-4)   (3-4)-(4-5)
5   (4-5)   (4-5)-(5-6)
6   (5-6)   (5-6)-(6-7)
7   (6-7)   (6-7)-(7-8)
8   (7-8)   (7-8)-(8-9)
9   (8-9)   (10-9)-(9-8) = (8-9)*2

>>> from numpy import *
>>> F = [[-1,0,0,0,0,0,0,0,0],
...            [1,-1,0,0,0,0,0,0,0],
...            [0,1,-1,0,0,0,0,0,0],
...            [0,0,1,-1,0,0,0,0,0],
...            [0,0,0,1,-1,0,0,0,0],
...            [0,0,0,0,1,-1,0,0,0],
...            [0,0,0,0,0,1,-1,0,0],
...            [0,0,0,0,0,0,1,-1,0],
...            [0,0,0,0,0,0,0,1,-1]]
>>>
>>> B = [[1,-1,0,0,0,0,0,0,0],
...            [0,1,-1,0,0,0,0,0,0],
...            [0,0,1,-1,0,0,0,0,0],
...            [0,0,0,1,-1,0,0,0,0],
...            [0,0,0,0,1,-1,0,0,0],
...            [0,0,0,0,0,1,-1,0,0],
...            [0,0,0,0,0,0,1,-1,0],
...            [0,0,0,0,0,0,0,1,-1],
...            [0,0,0,0,0,0,0,0, 2]]
>>>
>>> M = -matrix(B) * matrix(F)
>>> print M
[[ 2 -1 0 0 0 0 0 0 0]
 [-1 2 -1 0 0 0 0 0 0]
 [ 0 -1 2 -1 0 0 0 0 0]
 [ 0 0 -1 2 -1 0 0 0 0]
 [ 0 0 0 -1 2 -1 0 0 0]
 [ 0 0 0 0 -1 2 -1 0 0]
 [ 0 0 0 0 0 -1 2 -1 0]
 [ 0 0 0 0 0 0 -1 2 -1]
 [ 0 0 0 0 0 0 0 -2 2]]

If we apply this M operator, it generated massive cancellation errors.
Applying its inverse turn all entries non-negative, without cancellation errors.

>>> print linalg.inv(M)
[[ 1. 1. 1. 1. 1. 1. 1. 1. 0.5]
 [ 1. 2. 2. 2. 2. 2. 2. 2. 1. ]
 [ 1. 2. 3. 3. 3. 3. 3. 3. 1.5]
 [ 1. 2. 3. 4. 4. 4. 4. 4. 2. ]
 [ 1. 2. 3. 4. 5. 5. 5. 5. 2.5]
 [ 1. 2. 3. 4. 5. 6. 6. 6. 3. ]
 [ 1. 2. 3. 4. 5. 6. 7. 7. 3.5]
 [ 1. 2. 3. 4. 5. 6. 7. 8. 4. ]
 [ 1. 2. 3. 4. 5. 6. 7. 8. 4.5]]

We can also think of inv(M) as "going back in time", turning divergence into convergence. Smile
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Bürgi's Kunstweg to Calculate Sines - Albert Chan - 05-09-2022 04:55 PM



User(s) browsing this thread: 1 Guest(s)