The following warnings occurred:
Warning [2] Undefined array key 88862 - Line: 275 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 275 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined array key 88874 - Line: 275 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 275 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined array key 88876 - Line: 275 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 275 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined array key 88880 - Line: 275 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 275 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined array key 88881 - Line: 275 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 275 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined array key 88887 - Line: 275 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 275 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined array key 88916 - Line: 275 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 275 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined array key 88918 - Line: 275 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 275 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined array key 88937 - Line: 275 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 275 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined variable $thread - Line: 295 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 295 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Trying to access array offset on value of type null - Line: 295 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 295 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined variable $fid - Line: 295 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 295 errorHandler->error_callback
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined array key 88880 - Line: 331 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 331 errorHandler->error_callback
/inc/plugins/threaded_mode.php 332 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 332 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 304 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined array key 88887 - Line: 331 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 331 errorHandler->error_callback
/inc/plugins/threaded_mode.php 332 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 332 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 332 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 304 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined array key 88918 - Line: 331 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 331 errorHandler->error_callback
/inc/plugins/threaded_mode.php 332 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 332 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 332 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 332 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 304 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined array key 88937 - Line: 331 - File: inc/plugins/threaded_mode.php PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php 331 errorHandler->error_callback
/inc/plugins/threaded_mode.php 332 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 332 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 332 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 332 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 304 ThreadedMode::buildtree
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined variable $theme - Line: 3 - File: inc/plugins/threaded_mode.php(305) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php(305) : eval()'d code 3 errorHandler->error_callback
/inc/plugins/threaded_mode.php 305 eval
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Trying to access array offset on value of type null - Line: 3 - File: inc/plugins/threaded_mode.php(305) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php(305) : eval()'d code 3 errorHandler->error_callback
/inc/plugins/threaded_mode.php 305 eval
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined variable $theme - Line: 3 - File: inc/plugins/threaded_mode.php(305) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php(305) : eval()'d code 3 errorHandler->error_callback
/inc/plugins/threaded_mode.php 305 eval
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Trying to access array offset on value of type null - Line: 3 - File: inc/plugins/threaded_mode.php(305) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php(305) : eval()'d code 3 errorHandler->error_callback
/inc/plugins/threaded_mode.php 305 eval
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Undefined variable $lang - Line: 5 - File: inc/plugins/threaded_mode.php(305) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php(305) : eval()'d code 5 errorHandler->error_callback
/inc/plugins/threaded_mode.php 305 eval
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks
Warning [2] Attempt to read property "messages_in_thread" on null - Line: 5 - File: inc/plugins/threaded_mode.php(305) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/threaded_mode.php(305) : eval()'d code 5 errorHandler->error_callback
/inc/plugins/threaded_mode.php 305 eval
/inc/plugins/threaded_mode.php 23 ThreadedMode::showthread_threaded
/inc/class_plugins.php 142 threaded_mode_showthread_threaded
/showthread.php 918 pluginSystem->run_hooks





Newton's Method



#2

I'm having a little trouble. My textbook requires that I preform Newton's method on my calculator. They show how to do it on a TI-84 or something like that but I have a HP 49g+. Can anyone take me throught the steps? Thanks a lot.

John


#3

are you asking us to do your homework?

**vp


#4

No. I'm asking for help with working a calculator that I am unfamiliar with.

#5

The folloing code assumes that FX stores the function you want to solve:

<< 
"TOLERANCE" "1E-8" INPUT OBJ->
"GUESS" "" INPUT OBJ-> -> T X
<< 0 0 0 0 -> H D F I
<<
DO
'I' INCR DROP
X ABS 1 + 0.01 * 'H' STO
X FX 'F' STO
X H + FX F - INV H * F * 'D' STO
X D - 'X' STO
UNTIL D ABS T < I 55 > OR
END
I "ITERS" ->TAG
X "ROOT" ->TAG
>>
>>
>>

The program prompts you to enter the root tolerance and a guess for the root. The program displays the number of iterations and the last refined guess for the root. If the iterations exceed 55, the program exits.

Hope this will do the job.

Namir

PS: My consulting fees will be emailed to you. Shoudl email fail, Mr T will show up in person with the invoice. I strongly suggest paying him cash AND without delay!

:-)


Edited: 8 Mar 2006, 3:43 p.m.


#6

Thanks for the response, but I don't really follow how to do it.

John


#7

The code uses the basic Newton algorithm:

X(new) = X - f(X) / f'(X)

The code approximates the derivative f'(X) using:

f'(X) = (f(X+h) - f(X)) / h

where h = 0.01 * (1 + |X|). This expresion insures that h is just above 0.01 when X very small.

So the first equation becomes:

X (new) = X - h * f(X)/(f(X+h) - f(X))

Since f(X) appears twice, it's better to save it to a variable (F in the program).

The term f(X)/f'(X) is the guess refinement, stored in variable D in the program. Iteration stops when the absolute value of this refinement is less than the tolerance value (stored in variable T in the program).

Now here comes your part of the homework. Reconcile the code with the above information.


Edited: 8 Mar 2006, 10:33 p.m.

#8

From Namir:

<< 
"TOLERANCE" "1E-8" INPUT OBJ->
"GUESS" "" INPUT OBJ-> -> T X
<< 0 0 0 0 -> H D F I
<<
DO
'I' INCR DROP
X ABS 1 + 0.01 * 'H' STO
X FX 'F' STO
X H + FX F - INV H * F * 'D' STO
X D - 'X' STO
UNTIL D ABS T < I 55 > OR
END
I "ITERS" ->TAG
X "ROOT" ->TAG
>>
>>
>>

Quote:
PS: My consulting fees will be emailed to you. Should email fail, Mr T will show up in person with the invoice. I strongly suggest paying him cash AND without delay!

From John:

Quote:
Thanks for the response, but I don't really follow how to do it.

Neither do I, but I'll try it on my 48G or 49G.

"I pity the fool" who must program in RPL! ;-) Good thing that the 49G+ has equation solving built in.

-- KS


#9

Karl,

Using the Solver gets the HP calculator an A and John an F!!!

:-)

Namir

#10

Hi, Karl:

Karl posted:

""I pity the fool" who must program in RPL! ;-)"

    Indeed ! Especially as the algorithm itself is so simple. This would be the no-frills HP-71B version, and I'm sure everyone would agree it's much more understandable (line numbers are arbitrary and comments aren't needed, of course):
        100  ! Basic Newton's Method:  x1=x0-f(x)/f'(x)
    110 !
    120 ! Ask for initial guess and tolerance
    130 !
    140 INPUT "Initial guess=";X0 @ INPUT "Tolerance=";T @ D=.00001
    150 !
    160 ! Perform up to 50 iterations and output result
    170 !
    180 FOR I=1 TO 50 @ X1=X0-FNF(X0)/FND(X0)
    190 IF ABS(X1-X0)<T THEN PRINT "Root=";X1 @ END ELSE X0=X1
    200 NEXT I @ PRINT "No convergence after 50 iterations"
    210 !
    220 ! Derivative computation: f'(x)
    230 !
    240 DEF FND(X)=(FNF(X+D)-FNF(X-D))/(2*D)
    250 !
    260 ! Define your function below: f(x)
    270 !
    280 DEF FNF(X)=X^3-6*X-2
    where the equation being solved is x3-6x-2=0, simply defined at line 230 as FNF(X). For instance, to compute all three distinct roots:
      >RUN
    Initial guess = 2
    Tolerance = 1E-10

    Root = 2.60167913188

    >RUN
    Initial guess = 0
    Tolerance = 1E-10

    Root = -.339876886624

    >RUN
    Initial guess = -2
    Tolerance = 1E-10

    Root = -2.26180224527

    if no convergence occurs within 50 iterations (because the
    equations has no real roots, for instance), such as when
    f(x)=x2+1 = 0, this is what happens:
        >230 DEF FNF(X)=X^2+1

    >RUN
    Initial guess = 2
    Tolerance = 1E-10

    No convergence after 50 iterations

    An important difference between my HP-71B version and Namir's RPL one is that I compute the derivative using a much more accurate 2nd-order method (error proportional to h2) instead of the 1st-order method (error proportional to h) he uses. Not that great accuracy is required for Newton's method, mind you, and you need three calls to f(x) instead of only two, but then you have the bonus of being able to compute a fairly accurate derivative right from the keyboard by simply calling FND with your argument.

" Good thing that the 49G+ has equation solving built in."
    Oh, if built-in solvers are permitted then the HP-71B version is
    simply:
         PRINT FNROOT(0,3,FVAR^3-6*FVAR-2)

    2.60167913189

    where you can even omit the PRINT. I don't know why, but I strongly suspect that the 49G+ built-in equation solving process is still more complicated than that. As some clever contributor told me recently in a private communication:


      "I have to admit that RPL makes you focus more on the technicalities of the stack (DUP, DUP2, ROLL,
      ROLLD, OVER, PICK, etc...) rather than on your algorithms ..."

    I couldn't have said it better.

Best regards from V.


Edited: 9 Mar 2006, 6:57 a.m.


Possibly Related Threads…
Thread Author Replies Views Last Post
  A fast Bernoulli Number method for the HP Prime Namir 16 5,362 11-22-2013, 04:46 PM
Last Post: Namir
  A brand new calculator benchmark: "middle square method seed test" Pier Aiello 25 6,762 09-13-2013, 01:58 PM
Last Post: Pier Aiello
  Downhill Simplex Method (Nelder Mead) for WP-34S Marcel Samek 0 866 07-07-2013, 03:05 AM
Last Post: Marcel Samek
  New Quadratic Lagrangian Interpolation Method Namir 2 1,316 07-20-2012, 04:32 PM
Last Post: Namir
  New variant for the Romberg Integration Method Namir 8 2,440 04-18-2012, 07:47 AM
Last Post: Nick_S
  question for lyuka and the Ostrowski method - bumped! hugh steers 7 2,287 08-27-2011, 11:47 AM
Last Post: Namir
  question for lyuka and the Ostrowski method hugh steers 14 3,437 08-22-2011, 04:40 PM
Last Post: Lyuka
  Lyuka and the Ostrowski method's for Root Seeking Namir 1 932 08-20-2011, 11:03 AM
Last Post: Lyuka
  An Attempt to Challenge the Bisection method for root findin Namir 6 2,029 08-14-2011, 05:57 PM
Last Post: Paul Dale
  Further to an earlier posting, Method to the madness! Geoff Quickfall 6 1,721 03-16-2010, 09:38 PM
Last Post: Geoff Quickfall

Forum Jump: