[VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
|
04-05-2019, 01:58 AM
Post: #27
|
|||
|
|||
RE: [VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
Hi, all: At long last, today it's time for my final original solution, namely: Tier 5 - The Challenge: Consider the function cin(x) which has the defining property that cin(cin(cin(x))) = sin(x). Write a program or function which accepts an argument x in the range [-Pi, Pi] and outputs the corresponding value of cin(x) correct to at least 8-10 digits in the whole range. Use it to tabulate cin(x) for x = 0.0, 0.2, 0.4, ..., 1.0 and also to compute cin(Pi/2), cin(-0.71), cin(2.019). My original solution: My original solution for the HP-71B is the following user-defined function (plus initialization code): 1 DESTROY ALL @ OPTION BASE 1 @ DIM C(7) @ READ C 2 DATA 1,-1/18,-7/1080,-643/408240,-13583/29393280,-29957/215550720,-24277937/648499737600 3 DEF FNC(X) @ L=0 @ M=1/3 @ REPEAT @ X=SIN(X) @ L=L+1 @ UNTIL ABS(X)<M 4 S=0 @ FOR Z=1 TO 7 @ S=S+C(Z)*X^(2*Z-1) @ NEXT Z 5 FOR Z=1 TO L @ S=ASIN(S) @ NEXT Z @ FNC=S @ END DEF Instead of tabulating it for 0.0, 0.2, ..., 1.0 as I originally asked, let's better tabulate it for x from 0 to Pi/2 in steps of Pi/10: 6 FOR X=0 TO PI/2 STEP PI/10 7 Y=FNC(FNC(FNC(X))) @ DISP X;FNC(X);Y;SIN(X);Y-SIN(X) @ NEXT X >FIX 10 >RUN x cin(x) cin(cin(cin(x))) sin(x) Error ---------------------------------------------------------------------- 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0 0.3141592654 0.3124163699 0.3090169944 0.3090169944 -1.0E-12 0.6283185307 0.6138343796 0.5877852523 0.5877852523 2.2E-11 0.9424777961 0.8897456012 0.8090169944 0.8090169944 4.1E-11 1.2566370614 1.1122980783 0.9510565164 0.9510565163 1.0E-10 1.5707963268 1.2103683445 1.0000000000 1.0000000000 1.0E-11 So we've got 10 correct decimals or better, as the error in cin(x) is even smaller than the error in cin(cin(cin(x)))-sin(x) which doesn't exceed 10-10. As for the discrete values asked in the challenge: >FIX 10 @ FNC(PI/2); FNC(-0.71); FNC(2.019) 1.2103683445 -0.6887785253 1.0269233188 Notes:
That's all for Tier 5, I could say a whole lot more about this topic and post additional code and results but this post is long enough as it is so I'll stop right now. Thank you very much to Albert Chan, J-F Garnier, Oulan and Gerson W. Barbosa for your valuable contributions and to Werner for your interest, I hope you enjoyed it all ! V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)