No comment on p., but Numerical Recipes points out
that a better way to evaluate the quadratic equation
is
(%&a , c&%) - bby2 ([ + (* *)~) %: (*:bby2) - a * c
which avoids the precision problems of the 'usual means'
when a or c is small.
abc =. 0.0002 289.726 0.0002
'a bby2 c' =: abc * 1 0.5 1
- a %~ bby2 + _1 1 * %: (*:bby2) - a * c
_6.90363e_7 _1.44863e6
(%&a , c&%) - bby2 ([ + (* *)~) %: (*:bby2) - a * c
_1.44863e6 _6.90307e_7
(|.abc) p. {. - a %~ bby2 + _1 1 * %: (*:bby2) - a * c
_1.62038e_8
(|.abc) p. {: (%&a , c&%) - bby2 ([ + (* *)~) %: (*:bby2) - a * c
0
(|.abc) p. (1;1) {:: p. |. abc
0
Henry Rich
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Mike Day
> Sent: Monday, March 12, 2007 5:20 AM
> To: Programming forum
> Subject: [Jprogramming] performance of p. on quadratics
>
> Although I realise there must be quite a lot under
> the bonnet (hood in US) of monadic p. , I am still
> surprised by the following execution times,
> revealed when I tried to solve several hundred
> quadratics with the help of p. :
>
> NB. typical quadratic coefficients for my problem
> abc
> 208.071 289.726 2.83326
> p.|.abc NB. solving quadratic with p.
> +-------+--------------------+
> |208.071|_1.38259 _0.00984876|
> +-------+--------------------+
> NB. solving quadratic by usual means....
> 'a bby2 c' =: abc * 1 0.5 1
> - a %~ bby2 + _1 1 * %: (*:bby2) - a * c
> _0.00984876 _1.38259
> ts'p.|.abc'
> 0.0103994 18304
> ts'- a %~ bby2 + _1 1 * %: (*:bby2) - a * c'
> 3.24064e_5 2048
>
> My DIY version is over 300 times faster - at
> least in this well-behaved case.
>
> Is the relatively low speed a necessary price
> for recent improvements in the robustness of
> p. in J6.01?
>
> Mike
>
> PS - It's still great to have tools like p.
> available.
> ----------------------------------------------------------------------
> For information about J forums see
> http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm