HP 35s derivatives/extremums - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: HP 35s derivatives/extremums (/thread-250142.html) |
HP 35s derivatives/extremums - Richard Berler - 09-12-2013 The program for derivatives,extremums works beautifully on the HP 15C LE. I can't come up with something that works on the HP 35s as it handles complex numbers in a less complete manner ( or I'm just ignorant on this...). Any ideas? Here's a great post by Dieter that explained how it works on the HP 15C LE: It's done exactly the same way as in the previous example.
Define your function f(x) as usual. For instance like this:
Then simply call f(x) for your (real) x plus a small imaginary part h. 1 EEX 10 CHS STO 0
Enter the routine for the first derivative:
Re: HP 35s derivatives/extremums - Dieter - 09-12-2013 The original message can be found here (cf. message #30). You will also find a formatted version of the 15C code there. This method cannot be used directly on the 35s since it does not offer a direct way to decompose a complex number in order to obtain its complex part, as described in the LBL 1 routine of the 15C code. Which does not mean it cannot be done at all. ;-)
Dieter
Re: HP 35s derivatives/extremums - Matt Agajanian - 09-12-2013 A while ago I devised methods to decompose polar/rectangular values on the 35S. Yup!!!! And, to verify it's working corectly, I tried it with several examples from HP and TI manuals. Since it worked so well, I revised the method to decompose complex mumbers. And yes, I ran that algorithm several times with several examples and yes, my decomposition for complex mumbers procedure worked every time. Here it is: If a+bi is in X register, then
ENTER^
x<-->y Edited: 12 Sept 2013, 7:00 p.m.
Re: HP 35s derivatives/extremums - Richard Berler - 09-12-2013 Cool! Now I have an HP 35s that can do arc trig and hyperbolic trig functions of complex numbers from earlier programming, and now can find extremums of a function by solving f'(x)=0!
Thanks!
Re: HP 35s derivatives/extremums - Matt Agajanian - 09-12-2013 You're welcome. My pleasure. I'm glad that these can help. And, as you can probably tell, you could extract the real part first.
Edited: 12 Sept 2013, 11:56 p.m.
Re: HP 35s derivatives/extremums - Paul Dale - 09-13-2013 This community created the ultimate rectangular / polar routines soon after the 35S was released. They preserve the unused stack, set lastX correctly and operate independent of the equation prompting flag. You'd need some modifications to deal with complex numbers directly but they are a good basis for such work.
Re: HP 35s derivatives/extremums - Dieter - 09-13-2013 Quote:
Well, it can be done. Yesterday I first tried the method suggested by Matt to isolate the imaginary part. But I found it was not sufficiently exact for complex numbers where the imaginary part is rather small. According to my results, the better idea is determining the real part first, and then subtracting it to get a complex number with a zero real part. This way I got the following program that can evaluate zeros as well as minima and maxima. The function is the one used in the earlier thread from last May: y = -200 * (25 * (e-x/20 - 1) + x)So here's my crude and not much tested 35s code that illustrates how it may be done on that machine as well. Use at your own risk. ;-) F001 LBL F ; define function f(x)Now let's see what we get. The procedure is different from earlier HPs like the 34C or 15C since the 35s uses lettered variables for the solver.
First, provide an appropriate small value for h: 1E-6 STO HSecond, define the derivative D as the function to solve: FN= DThe local maximum is somewhere between 0 and 10: 0 STO X 10 We may also try the other example of the original post:
y = x2 - 3x - 10First, find a root between x = 0 and x =12. FN= FFind the negative root as well: 0 STO X -12Now find the minimum between the two roots: FN= DI am sure there are better and more reliable ways to obtain the imaginary part of a complex number. As usual, any suggestions are welcome.
Dieter
Re: HP 35s derivatives/extremums - Richard Berler - 09-13-2013 Hi Dieter, The F program works, but I get no roots found on both attempts of the D program with the exact keystrokes that you gave on both examples. Can you check the D program again to see if there was a typo or a missing step? Thanks!
Re: HP 35s derivatives/extremums - Richard Berler - 09-13-2013 found it...in D, after D010, we need to insert x<>y as D011!
Re: HP 35s derivatives/extremums - Richard Berler - 09-14-2013 On all platforms...34s, 15C, 50g..., minimums that occur for x<0 seem problematic for derivative programs for equations such as x^(5/3) + 5*x^(2/3). I don't get the min at -2 on these calculators with built in programs (tabvar) on 50g, solving for f'(x)=0 on the 34, and the complex method on the 35s and 15C.
Re: HP 35s derivatives/extremums - Paul Dale - 09-14-2013 This function can be minimised if you use the cube root rather than yx directly.
LBL A
-3 ENTER -1.5 SLV B gives -2.000000000024174
Re: HP 35s derivatives/extremums - Dieter - 09-14-2013 Richard, the version I posted works fine. Of course you may replace the "roll down" command in line D011 with a "x<>y", if you prefer. But the original program returns correct results as well. I just checked it on a 35s (real hardware, not an emulator). After the function call XEQ F001 the stack's x-register holds the complex result f(x+ih). The next three steps only restore the original (real) X and drop the stack so that the x-register holds f(x+ih) again.
Dieter
Re: HP 35s derivatives/extremums - Richard Berler - 09-14-2013 My mistake...I thought "rnd" was for the rounding function as opposed to roll down! Didn't know why that was necessary, and of course, the program was impacted adversely. It did make me feel some sort of accomplishment to diagnose what was missing :)
Re: HP 35s derivatives/extremums - Matt Agajanian - 09-14-2013 Actually, although that fantastic routine works very well for polar/rectangular conversions in the usual two-register stack form, it doesn't decompose X-Register a+bi formed complex numbers on the 35S.
Edited: 14 Sept 2013, 4:57 p.m.
Re: HP 35s derivatives/extremums - Dieter - 09-15-2013 You are absolutely right - RND is the round function, but that's not what the code says. D011 is not RND, but RDN. ;-) Finally, here's a complete solution for zeros and extremes of a function. This time I tried the 35s emulator. Compared to the previous version the handling is much nicer and more comfortable.
Y001 LBL Y And here's how to use it:
0. Enter programHere's an example: y = x^3 - x^2 - x + 1/2And finally here's the function used in the May 2013 thread: Y001 LBL YAgain, this program is a quick and dirty version that may have errors and other flaws. Use at your own risk, improve as you like and don't forget to share your improvements here. ;-) Dieter
Edited: 15 Sept 2013, 10:07 a.m.
Re: HP 35s derivatives/extremums - Dieter - 09-15-2013 Quote:That's not yet minimized. ;-) LBL ADieter Re: HP 35s derivatives/extremums - Dieter - 09-15-2013 No problem - a minor tranformation does the trick: x5/3 + 5 x2/3The current program version for the 35s returns the desired solution: Y001 LBL YI assume this approach should also work with other calculators. Dieter
Edited: 15 Sept 2013, 11:03 a.m.
|