Post Reply 
[VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
04-01-2019, 04:42 PM (This post was last modified: 04-01-2019 06:29 PM by J-F Garnier.)
Post: #23
RE: [VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
(04-01-2019 03:25 PM)Albert Chan Wrote:  Just figured out how to improve cin(x) accuracy for large x Smile

cin(x) = arcsin(cin(sin(x))) = nest(arcsin, cin(nest(sin, x, n)), n)

Pick enough nested sin's so cin argument is small, say below 0.1 radian

cin[x0_] := Block[ {n=0, x=Evaluate[x0+0.0]},
    While[Abs[x] ≥ 0.1, x = Sin[x]; n++];
    Nest[ArcSin, x - (1/18) x^3 - (7/1080) x^5 - 0.00158 x^7, n]
]
...

Excellent !
Here is the HP71 version and results, after decipher of your code (not familiar with that language...):

10 ! SSMC24
20 A=-1/18 @ B=-7/1080 @ C=-.00158
30 DEF FNC(X)
40 N=0
50 X=SIN(X) @ N=N+1 @ IF ABS(X)>=.1 THEN 50
60 ! X=X+A*X^3+B*X^5+C*X^7
61 X=C*X^7+B*X^5+A*X^3+X ! better
70 FOR I=1 TO N @ X=ASIN(X) @ NEXT I
80 FNC=X
90 END DEF
100 !
110 FOR X=.2 TO 1 STEP .2
120 Y=FNC(FNC(FNC(X)))
130 PRINT X;Y;SIN(X);Y-SIN(X)
140 NEXT X

>RUN
.2 .198669330795 .198669330795 0
.4 .389418342314 .389418342309 .000000000005
.6 .564642473542 .564642473395 .000000000147
.8 .717356091570 .717356090900 .000000000670
1. .841470984040 .841470984808 -.000000000768

>FNC(PI/2);FNC(FNC(FNC(PI/2)))
1.2103683495 .999999998579

>FNC(-0.71)
-.688778525229

>FNC(2.019)
1.02692332142

J-F
[Edited: reversed the order of the polynom term evaluation, for slightly better accuracy]
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier" - J-F Garnier - 04-01-2019 04:42 PM



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