Post Reply 
A somewhat different Newton solver (HP35s)
08-07-2016, 08:47 PM (This post was last modified: 08-07-2016 08:48 PM by Dieter.)
Post: #1
A somewhat different Newton solver (HP35s)
I think most of us will know the usual Newton method for finding the roots of a function. This requires the evaluation of the function f(x) as well as its derivative f'(x), which usually means two function calls per iteration step.

For a project where the derivative cannot be calculated fast and easily I now tried the following method that is based on a method already discussed earlier, e.g. here and there. The idea here is the simulaneous calculation of f(x) and f'(x) via complex math. On the 35s this can be done quite easily – at least within the supported function set.

Here is a sample program to illustrate the idea.

Code:
S001 LBL S
S002 INPUT X
S003 1E-6
S004 STO H
S005 i
S006 RCLx H
S007 RCL+ X
S008 XEQ F001
S009 ARG
S010 COS
S011 LASTX
S012 SIN
S013 /
S014 RCLx H
S015 STO- X
S016 FIX 6
S017 RND
S018 X≠0?
S019 GTO S005
S020 RCL X
S021 VIEW X
S022 GTO S001

F001 LBL F
F002 ENTER
F003 ENTER
F004 ENTER
F005 1
F006 -
F007 x
F008 1
F009 -
F010 x
F011 0,5
F012 +
F013 RTN

Please note: this is just to show the idea, not a fully working program. ;-)

Steps S009...S014 calculate the quotient of the real (approx. f(x)) and imaginary parf (approx. f'(x)). The sine and cosine should not be replaced by 1/tangent since f(x)=0 will yield a real part of ±90° where the tangent is not defined (a cotangent function would be nice here...).

Example:

Code your function f(x) at LBL F, assuming the argument x in the X-register. The sample function is x³–x²–x+0,5 = 0. After XEQ S enter an initial guess for x.

Code:
[XEQ] S [ENTER]     X?
      0 [R/S]       X= 0,403032

[XEQ] S [ENTER]     X?
      2 [R/S]       X= 1,451606

[XEQ] S [ENTER]     X?
     -2 [R/S]       X=-0,854638

So this seems to work.

What about limitations of this method? As far as I get it both f(x) as well as f'(x) are only approximate. I wonder how accurate especially f(x) is evaluated using this method. Maybe the math experts here can say more about this. ;-)

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
A somewhat different Newton solver (HP35s) - Dieter - 08-07-2016 08:47 PM



User(s) browsing this thread: 1 Guest(s)