These seem to work OK but I'm unsure about the precision requirement which
seems to be required by sslope:

   New1=: 1 : 'y-(u y)%1e_12 u sslope_jcalculus_ 1]y'
   New1ton=: 1 : 'u New1 ^: _ ] y'

   NB. From "wiki/Fifty_Shades_of_J":
   f1=: _2 _1 1&p."0
   f2=. (2&o. - (*^))"0     NB. cos(x) – x * exp(x)
   f3=: (2 0 0 _1&p.)"0     NB. 2 – x^3
   f1 New1ton 1
2
   f2 New1ton 1
0.517757
   f3 New1ton 1
1.25992

Allowing the precision requirement in from the top:

   New2=: 2 : 'y-(u y)%n u sslope_jcalculus_ 1]y'
   New2ton=: 2 : 'u New2 n ^: _ ] y'

   f1 New2ton 0.0001 ] 1
2
   f2 New2ton 0.0001 ] 1
0.517757
   f3 New2ton 0.0001 ] 1
1.25992

But it's not clear how important precision is in this context - maybe " ^:_
" obviates it?
   f1 New2ton 1 ] 1
2
   f2 New2ton 1 ] 1
0.517757
   f3 New2ton 1 ] 1
1.25992

I can't decide if it's better to fix precision at a deep level or not.
Better yet, factor it out entirely.  One of the nice uses of Newton used to
be to apply it with an extended precision argument to calculate, e.g. %:2,
to arbitrary precision.

   18j16": (_2 0 1&p.) New2ton 1 ] 1
1.4142135623730836
   18j16": (_2 0 1&p.) New2ton 1e_15 ] 1
1.4142135623730958
   18j16": (_2 0 1&p.) New2ton 1e_15 ] 1x
1.4142135623730958
   18j16": (_2 0 1&p.) New2ton 1e_20 ] 1x
|NaN error: New2
|   ((x func"(#@$y)newy)    -"(#@$f0)f0)%x



On Sat, Jan 16, 2021 at 12:19 AM Devon McCormick <[email protected]> wrote:

> I'm using what is given in the essay, trying to change as little as
> possible.  However the polynomial version is more straightforward.
>
> On Fri, Jan 15, 2021 at 11:10 PM Henry Rich <[email protected]> wrote:
>
>> A reasonable expectation.  sslope_jcalculus_ provides an approximation
>> to the slope.  A user could write a conjunction to use that if
>> deriv_jcalculus_ can't find a closed-form derivative.
>>
>> But: #.&1 _1 _2&> opens its argument.  Can there ever be a derivative of
>> a boxed argument?
>>
>> Henry Rich
>>
>> On 1/15/2021 10:48 PM, Devon McCormick wrote:
>> > I guess I was expecting a numerical solution if a symbolic one is not
>> found.
>> >
>> > On Fri, Jan 15, 2021 at 10:05 PM Henry Rich <[email protected]>
>> wrote:
>> >
>> >> What do you expect the derivative of #.&1 _1 _2&> to be?
>> >>
>> >> I see that #.&1 _1 _2 has no derivative, but 1 _1 _2&p. does.
>> >>
>> >> Deficiencies in math/calculus are not 'issues'.  They are opportunities
>> >> for improvement by users.
>> >>
>> >> Henry Rich
>> >>
>> >> On 1/15/2021 9:37 PM, Devon McCormick wrote:
>> >>> I tried to update chapter 23 of the "50 Shades of J" essay using the
>> new
>> >>> version of Newton's method from "
>> >>> https://code.jsoftware.com/wiki/Essays/Newton%27s_Method"; but this
>> >> breaks
>> >>> examples in "50 Shades", e.g.
>> >>>
>> >>>      f1=: #.&1 _1 _2&>   NB. Function to use
>> >>>      Newton=: adverb : ']-u % (u deriv_jcalculus_ 1'
>> >>>      f1 Newton 1
>> >>> |domain error: deriv_jcalculus_
>> >>> |       13!:8(3)
>> >>> |deriv_jcalculus_[:19]
>> >>>
>> >>> Is this a known issue?
>> >>>
>> >>> I've left my "fix" in as the existing code will also break in the
>> current
>> >>> version of J.
>> >>>
>> >>
>> >> --
>> >> This email has been checked for viruses by AVG.
>> >> https://www.avg.com
>> >>
>> >> ----------------------------------------------------------------------
>> >> For information about J forums see http://www.jsoftware.com/forums.htm
>> >>
>> >
>>
>>
>> --
>> This email has been checked for viruses by AVG.
>> https://www.avg.com
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>
>
> --
>
> Devon McCormick, CFA
>
> Quantitative Consultant
>
>

-- 

Devon McCormick, CFA

Quantitative Consultant
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to