Post Reply 
Reducing the Number of Slope Evaluations for Newton's Method
11-12-2024, 10:21 AM (This post was last modified: 11-12-2024 10:46 AM by C.Ret.)
Post: #6
RE: Reducing the Number of Slope Evaluations for Newton's Method
Hi,

Thanks to both of you for this interesting topic about Newton's Method to find the roots of a function.
Indeed, having to determine the derivate can induce more numerous evaluations of the function it self. But the idea is that a good determination will certainly lead more directly to the root.

Please let me share below my version of Namir's code that I modified so that the definition of the function is in the F1 slot of the Function Application.
In doing so, I said to myself that on an HP Prime, once the function is entered in the F1 slot, it is very easy to symbolically determine the derivative and store it in the F2 slot in order to facilitate the progress of the algorithm. We then save a good chunk of code and variables. However, my counter then counts the number of evaluations of F1(x) and F2(x). In a way, my counter runs half as fast as Namir's.


EXPORTNewton(x,tol)
BEGIN
  LOCAL dx:=2*tol, cnt:=0;
  F2 := REPLACE(STRING(CAS("diff(F1(z),z)")),"z","X");
  WHILE ABS(dx)>tol DO
      dx :=F1(x) / F2(x);
      cnt := 1+cnt;
      IF cnt>99 THEN BREAK(2); END;
      x := x - dx; 
  END;
  RETURN [ x, cnt ];
END;


I don't know if all this makes sense, on the HP Prime, other root-seeking methods exists.
The only advantage to my code is that it is possible to add graphic objects in order to have a pedagogical illustration of the method.

Actually, the unique advantage is to easily change from one function to another; just edit the F1 slot.

[Image: attachment.php?aid=14286] [Image: attachment.php?aid=14287]

Best regards.
C.Ret


Attached File(s) Thumbnail(s)
       
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Reducing the Number of Slope Evaluations for Newton's Method - C.Ret - 11-12-2024 10:21 AM



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