

|
 |
| Programming > Forth > Re: Taylor seri... |
|
| << Topic |
< Post |
Post 2 of 6 Topic 4019 of 4065
|
Post > |
Topic >> |
Re: Taylor series FSIN, FCOS, FTAN
by Albert van der Horst <albert@[EMAIL PROTECTED]
>
Apr 27, 2008 at 10:30 AM
| In article
<16edbcc0-0978-4a9c-aa82-d68c0773c9f4@[EMAIL PROTECTED]
>,
The Beez' <hansoft@[EMAIL PROTECTED]
> wrote:
>Thanks for your replies! I've come up with these ones, based on the
>Taylor series. It requires a separate FP stack and can't be used for
>large values as well, (which function should I use, Albert, to reduce
>this one?), but it is rather simple and relatively accurate.
For large values you should do range reduction. It amount to
subtraction multiples of 2*pi and such. At least try to land
in the [-PI, PI] interval.
It is wise to at least take that from the sources I supplied. This
greatly affects precision. If you omit range reduction, with your
Taylor series, it still works in principle.
For Chebychev it breaks down.
in the
>
>Hans Bezemer
>
>[UNDEFINED] fsin [IF]
>[UNDEFINED] floats [IF]
>include lib/ansfloat.4th
>[THEN]
>
>: f-rot frot frot ; \ inverted frot
>: >taylor fdup f* fover ; \ setup for Taylor series
>: (taylor) fover f* frot fover s>f f/ ;
>: +taylor (taylor) f+ f-rot ; \ add Taylor iteration
>: -taylor (taylor) f- f-rot ; \ subtract Taylor iteration
>
>: fsin
> fdup >taylor ( x x2 x)
> 6 -taylor ( x-3 x2 x3)
> 120 +taylor ( x+5 x2 x5)
> 5040 -taylor ( x-7 x2 x7)
> 362880 +taylor ( x+9 x2 x9)
> 39916800 -taylor ( x-11 x2 x11)
> fdrop fdrop ( x-11)
>;
>
>: fcos
> 1 s>f fswap >taylor ( 1 x2 1)
> 2 -taylor ( 1-2 x2 x2)
> 24 +taylor ( 1+4 x2 x4)
> 720 -taylor ( 1-6 x2 x6)
> 40320 +taylor ( 1+8 x2 x8)
> 3628800 -taylor ( 1-10 x2 x10)
> 479001600 +taylor ( 1+12 x2 x12)
> fdrop fdrop ( 1-10)
>;
>
>: ftan fdup fsin fswap fcos f/ ; \ ftan = fsin / fcos
>
>[DEFINED] 4TH# [IF]
>hide (taylor)
>hide +taylor
>hide -taylor
>hide >taylor
>[THEN]
>[THEN]
>
>fclear 100 set-precision
>s" 0.7854" s>float fsin f.
>s" 0.7854" s>float fcos f.
>s" 0.7854" s>float ftan f.
>cr
"State of the art" is to strive for last bit precision and a
separate way to calculate atan.
But this is simple and elegant and will do for government work.
Groetjes Albert.
--
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- like all pyramid schemes -- ultimately falters.
albert@[EMAIL PROTECTED]
&=n http://home.hccnet.nl/a.w.m.van.der.horst


|
6 Posts in Topic:
|
"The Beez'" < |
2008-04-26 04:12:45 |
|
Albert van der Horst < |
2008-04-27 10:30:59 |
|
"The Beez'" < |
2008-04-27 08:32:25 |
|
Albert van der Horst < |
2008-04-27 17:04:51 |
|
"The Beez'" < |
2008-04-27 08:45:45 |
|
"The Beez'" < |
2008-04-28 02:33:38 |
|
Post A Reply:

|
|
|
|