[Jprogramming] Another Quora Problem
Louis de Forcrand
olius at bluewin.ch
Mon Jan 29 17:36:23 UTC 2018
I would recommend using D. instead of d. in general for more complicated or explicit verbs. (lower case) d. assumes your verb is a scalar verb and tries to perform a symbolic differentiation on tacit verbs only, while D. differentiates numerically.
Not all verbs can be differentiated with d., but all can be with D.
Make sure to set your verb to the appropriate rank when using D. though, as otherwise it will perform a vector derivative if given a vector argument.
Cheers,
Louis
> On 29 Jan 2018, at 18:15, Skip Cave <skip at caveconsulting.com> wrote:
>
> What are the rules required to re-format a verb to make it processable by N?
>
> The original equation:
> (2^x) - 2^2*x = _8
>
> The reformatted equation:
> (8: + (2&^) - (2&^)@(2&*))
>
> Why the colon?
>
> Why the @ sign?
>
> Why the ampersand?
>
> Why not make a monadic verb?:
>
> v =: 3 : '8 + (2^y) - (2^2*y)'
> vv =: (8: + (2&^) - (2&^)@(2&*))
>
> v 1
>
> 6
>
>
> vv 1
>
> 6
>
>
> NB. Both verbs are the same, but:
>
>
> v N (^:20) 1
>
> |domain error
>
> | v N(^:20)1
>
>
> vv N (^:20) 1
>
> 1.75372
>
>
> ??
>
>
> Skip Cave
> Cave Consulting LLC
>
>> On Mon, Jan 29, 2018 at 3:12 AM, Rob Hodgkinson <rhodgkin at me.com> wrote:
>>
>> Minor correction Raul (- instead of +) ?
>> ... use (8: + (2&^) - (2&^)@(2&*))
>>
>> So Skip, just to clarify to see this solution put through Newton-Raphson;
>>
>> 1) Create the Newton-Raphson adverb as you stated earlier;
>>
>>
>> N=: 1 : '- u % u d. 1’
>>
>> 2) Apply for a number of iterations using ^: and give it an initial value
>> of 1 … fn N (^:iterations) start-value
>>
>>
>>
>> (8: + (2&^) - (2&^)@(2&*))N (^:20) 1
>> 1.75372
>>
>> 9!:11]14 NB. or increase print precision
>> (8: + (2&^) - (2&^)@(2&*))N (^:20) 1
>> 1.7537248941553
>>
>> Hope that clarifies things, as without the function appropriately defined
>> as Raul described, N returns a Domain Error if it can’t work with the
>> function.
>>
>> Rob
>>
>>> On 29 Jan 2018, at 7:57 pm, Raul Miller <rauldmiller at gmail.com> wrote:
>>>
>>> d. 1 wants to be able to use the chain rule for 2^2*x, and it seems
>>> like the implementation was from an early version of J, and has not
>>> kept up with all the more recent changes. So, you should put that
>>> changed term into an f at g form.
>>>
>>> In other words, use (8: + (2&^) + (2&^)@(2&*))
>>>
>>> Thanks,
>>>
>>> --
>>> Raul
>>>
>>>
>>> On Mon, Jan 29, 2018 at 1:46 AM, Skip Cave <skip at caveconsulting.com>
>> wrote:
>>>> I see what I did wrong.
>>>>
>>>> The equation is: 8 + (2^x) - 2^2*x = 0
>>>>
>>>> The third term is (2^2*x) not (2^2^x)
>>>>
>>>> That should get close to the answer x=1.75372
>>>>
>>>> I'm mostly interested in how to formulate the code to implement the
>> Newton
>>>> Raphson solution
>>>> using
>>>>
>>>> N=: 1 : '- u % u d. 1'
>>>>
>>>> In the NR code, where does the equation verb go?
>>>> How does it need to be structured? Where does the iteration count limit
>> go?
>>>>
>>>> Skip
>>>>
>>>>
>>>>
>>>>
>>>> Skip Cave
>>>> Cave Consulting LLC
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list