Thank you for pointing out that my calculation of f...@g t.i.n fails when g 0 is nonzero. I was mistaken.
Thank you also for teaching me that j.&0 ] 1r3 evaluates to the floating point number 0.333333 --- Den man 10/5/10 skrev Mark Niemiec <[email protected]>: > Fra: Mark Niemiec <[email protected]> > Emne: Re: [Jprogramming] Taylor expansion of sin(sin(x)) > Til: "J Programming Forum" <[email protected]> > Dato: mandag 10. maj 2010 10.11 > Bo Jacoby <[email protected]> > wrote: > > ?? 1&o.^:2 t.i.10x NB. Why does sin sin x produces > an > > error message? > > |domain error > > |?????? 1&o.^:2 t.i.10 > > ? (1&o.t.i.10)&p.^:2 t.i.10 NB. this trick > works around the bug > > 0 1 0 _1r3 0 1r10 0 _8r315 0 13r2520 > > Roger Hui <[email protected]> > replied: > > 1&o.^:2 t. signals domain error because > > u t. does a table look-up and 1&o.^:2 is not > > in the table. > > > > Are you claiming that if f t. and g t. both > > work then f...@g t. should work? > > Taylor series are just polynomials (possibly with infinite > numbers of terms). > As such, certain compositions of functions can be easily > simulated. > taylorplus =: 2 : 'u t.+v t.' NB. > (u+v)t. > taylortimes =: 2 : '+/@(u t.*|.@(v > t.))@i.@>:' NB. (u*v)t. > > One could similarly model u@:v t. > polyplus =: +/@:,: NB. Polynomial > addition (not used here) > polytimes =: +//.@:(*/) NB. Polynomial > multiplication > polypow =: polytimes^:([`]`1:) NB. > Polynomial power > taylorat =: 2 : 'y{+/(u t.@:]*(v > t.i.>:y) polypow ])"0 i._' NB. u@:v t. > > Unfortunately, J does not support sums of infinite series. > There are two cases where the infinite series can be > calculated finitely: > 1) If u has a finite Taylor expansion with only the first n > terms non-zero, > i._ can be replaced by i.n > 2) If 0=v t.0 (which happens with functions like 1&o.), > all terms beyond the > first >:y terms are zero at powers y > and below, so i._ can be > replaced by i.>:y > > Thus, your example just happens to work for 1&o. > taylorat2 =: 2 : 'y{+/(u t.@:]*(v > t.i.>:y) polypow ])"0 i.>:y' > sin taylorat2 sin"0 i.10 > 0 1 0 _0.333333 0 0.1 0 _0.0253968 0 0.00515873 > 0 j.~(1&o.t.i.10)&p.^:2 t.i.10 > NB. (0 j.~y forces conversion to real) > 0 1 0 _0.333333 0 0.1 0 _0.0253968 0 0.00515873 > > But similar techniques won't work for 2&o. or any other > function with > non-zero constant terms. For example: > (2&o.t.i.10)&p.^:2 t.i.10 > 4357r8064 0 4241r10080 0 _1241r12096 0 _1159r226800 0 > 12521r2540160 0 > (2&o.t.i.8)&p.^:2 t.i.8 > 389r720 0 101r240 0 _37r360 0 _53r10800 0 > > -- Mark D. Niemiec <[email protected]> > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
