Finding Min/Max of a function for HP-67
|
03-10-2014, 05:48 PM
Post: #1
|
|||
|
|||
Finding Min/Max of a function for HP-67
finding the minimmum/maximum of a function using Newton's method.
Memory Map R0 = tolerance R1 = x R2 = h R3 = f(x), f''(x) R4 = f(x+h) R5 = f(x-h) HP-67 Implementation Code: 1 LBL A Usage LBL E has the code for the function whose minimum or maximum you seek. 1) Enter the tolerance and press [ENTER]. 2) Enter a guess for the minimum/maximum and pres [A]. 3) The program pauses showing intermediate values for the refined min/max values. When the program has reached the tolerance level it displays the value of the X for the min/max value. |
|||
04-26-2014, 12:30 AM
Post: #2
|
|||
|
|||
RE: Finding Min/Max of a function for HP-67
Very nice! Thanks.
|
|||
05-26-2014, 12:14 PM
Post: #3
|
|||
|
|||
RE: Finding Min/Max of a function for HP-67
Thank you for sharing.
A pity the listings don't come with key codes. This would allow me to copy/paste the programs right into my HP-67/97 emulators for the iPad... |
|||
05-26-2014, 10:13 PM
(This post was last modified: 05-26-2014 10:31 PM by Thomas Klemm.)
Post: #4
|
|||
|
|||
RE: Finding Min/Max of a function for HP-67
(05-26-2014 12:14 PM)Willy R. Kunz Wrote: A pity the listings don't come with key codes. Code: 001 31 25 11 LBL A Cheers Thomas |
|||
05-26-2014, 10:13 PM
Post: #5
|
|||
|
|||
RE: Finding Min/Max of a function for HP-67
Namir - Nice program
Any reason to take out and use my HP-67 is a good one. Thanks for that! --Bob Prosperi |
|||
06-08-2014, 04:08 PM
(This post was last modified: 07-11-2014 01:24 PM by Willy R. Kunz.)
Post: #6
|
|||
|
|||
RE: Finding Min/Max of a function for HP-67
(05-26-2014 10:13 PM)Thomas Klemm Wrote: Thanks, Thomas. Very kind of you. This also prompted me to have a hard look at RPN-67/97's import capabilities. The result being that in the next update the emulators will accept listings without key codes. In fact, you can now enter and edit programs by simply typing calculator function names in the listing area. All of Namir's programs shown here run without any editing after pasting. UPDATE: RPN-67 Pro v2.5 and RPN-97 Pro v1.5 are now available, featuring the new import capabilities. Also in these updates: for the first time ever, real breakpoints to help you debug your program. |
|||
05-21-2016, 10:50 PM
Post: #7
|
|||
|
|||
RE: Finding Min/Max of a function for HP-67
(05-26-2014 10:13 PM)Thomas Klemm Wrote: [quote='Willy R. Kunz' pid='12139' dateline='1401106474'] Dear Thomas: I am using HP 67 SD, I got for Tolerance=5x10-4 and a guessing initial number of 9, a final figure of 2,833144107. Is this correct ? Now some basic questions please: 1- What equation represents steps 55-62? How I entry an equation to be evaluated? 2- From my example 2,833 is a Max. or a min.? How to obtain both if corresponds? Thank you in advance, Pedro |
|||
05-22-2016, 01:11 AM
Post: #8
|
|||
|
|||
RE: Finding Min/Max of a function for HP-67
(05-21-2016 10:50 PM)PedroLeiva Wrote: 1- What equation represents steps 55-62? How I entry an equation to be evaluated? As usual, you enter f(x) at LBL E. The argument x is expected in the X-register. Here f(x) obviously is ex–3x². (05-21-2016 10:50 PM)PedroLeiva Wrote: 2- From my example 2,833 is a Max. or a min.? How to obtain both if corresponds? Since f"(x) is stored in R3, you could simply inpect this value (RCL 3) an see whether it's positive (minimum) or negative (maximum). Here the function has a minimum at x=2,833147892... (solution of f'(x) = ex–6x = 0). At ths point f"(x) = ex–6 is 10,998887... > 0, so this is a minimum. The content of R3 should be close to the latter value. Dieter |
|||
05-22-2016, 01:26 AM
Post: #9
|
|||
|
|||
RE: Finding Min/Max of a function for HP-67
(05-22-2016 01:11 AM)Dieter Wrote:Dieter(05-21-2016 10:50 PM)PedroLeiva Wrote: 1- What equation represents steps 55-62? How I entry an equation to be evaluated? It's more complicated than I imagined. Luckily I made the query. Thank you very much, Peter |
|||
05-22-2016, 07:34 PM
(This post was last modified: 05-22-2016 07:36 PM by Dieter.)
Post: #10
|
|||
|
|||
RE: Finding Min/Max of a function for HP-67
(05-22-2016 01:26 AM)PedroLeiva Wrote: It's more complicated than I imagined. Luckily I made the query. Hmmm... honestly, I do not quite understand the problem. You simply enter f(x) as a short routine just as you do with any other "classic" HP, be it the 65, the 41, the 67/97 or most others. The argument x can be expected in the X-register, so you simply type what you'd also do in a manual calculation. In this example f(x) is ex–3x², so it's [ex] [LstX] [x²] [3] [x] [–]. This is what you enter at LBL E so that f(x) can be calculated by a simple [E] or GSB E. Checking for a minimum or maximum is easily done by RCL 3 after the program has finished. If the result is positive it's a minimum, and if it's negative there's a maximum. A value of (or very close to) zero would indicate a possible inflection point, but this should not happen as the program divides by R3 so that it would have stopped with an error before. You could add these lines: Code: ... ... This calculates –sign(f"(x)). So after the program has finished, a simple X<>Y will show –1 (minimum) or +1 (maximum). Dieter |
|||
05-22-2016, 10:35 PM
Post: #11
|
|||
|
|||
RE: Finding Min/Max of a function for HP-67
This calculates –sign(f"(x)). So after the program has finished, a simple X<>Y will show –1 (minimum) or +1 (maximum).
Dieter [/quote] The point is that in the original post of this program was no explanation about how to determine Max. or min. (or I did not realize). From the two options for cheking, I prefer: x<>y (+1, -1), for Max. & min., respectively. This one is more intuitive (+ is related to Max.), the other procedure is inverse. Thank you for clarifying this math issue, and modifying the program Pedro |
|||
05-23-2016, 01:08 PM
Post: #12
|
|||
|
|||
RE: Finding Min/Max of a function for HP-67
(05-22-2016 10:35 PM)PedroLeiva Wrote: The point is that in the original post of this program was no explanation about how to determine Max. or min. (or I did not realize). The program implements a simple Newton iteration to find the zeroes of the derivative f'(x). In a minimum or maximum f'(x) must be zero, and this is what the program finds. It evaluates x_new = x – f'(x) / f"(x). (05-22-2016 10:35 PM)PedroLeiva Wrote: From the two options for cheking, I prefer: x<>y (+1, -1), for Max. & min., respectively. This is what the proposed code does. It returns +1 for a maximum and –1 for a minimum. Dieter |
|||
05-23-2016, 07:37 PM
Post: #13
|
|||
|
|||
RE: Finding Min/Max of a function for HP-67
Examples:
Equation (began step 061) ex–3x² Tolerance= 1x10-5 Initial guess: 9……………X= 2,83314411………..min…………..Y= -7,08129358 Initial guess: 0,1…………X= 0,20448151……….Max…………..Y= 1,10145071 For X=0……………………Y= 1 For Y=0……………………X= 0,91 For the original equation, input TOLERANCE [ENTER] 9 [A] you get 2,8331, [x<>y] -1 so you know that is a minimun. Later, [x<>y] [E] you get Y=-7.081 wich is the Y value for the min. When X=0 [E] you get Y=1, that is to say intercept The value of X when Y=0 was solved by iteraction Follow the same procedure for the Maximun Pedro |
|||
05-23-2016, 08:00 PM
Post: #14
|
|||
|
|||
RE: Finding Min/Max of a function for HP-67
(05-26-2014 10:13 PM)Thomas Klemm Wrote:(05-26-2014 12:14 PM)Willy R. Kunz Wrote: A pity the listings don't come with key codes. Thanks Thomas! I was able to copy and paste to my iPhone's RPN-67 SD and it works like a charm! Regards, Bob |
|||
05-24-2016, 06:47 AM
Post: #15
|
|||
|
|||
RE: Finding Min/Max of a function for HP-67
I found a pretty good article about the concept at
http://www.themathpage.com/acalc/max.htm It helped me to understand what's happening with this program. Regards, Bob |
|||
05-28-2016, 08:09 PM
Post: #16
|
|||
|
|||
RE: Finding Min/Max of a function for HP-67
I found a pretty good article about the concept at
http://www.themathpage.com/acalc/max.htm It helped me to understand what's happening with this program. Regards, Bob |
|||
05-28-2016, 09:43 PM
Post: #17
|
|||
|
|||
RE: Finding Min/Max of a function for HP-67
(05-28-2016 08:09 PM)bshoring Wrote: I found a pretty good article about the concept at Excellent webpage, also for the others 14th. lessons. Thank´s for sharing Pedro |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)