HP 42S Question - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: HP 42S Question (/thread-12350.html) |
HP 42S Question - lrdheat - 02-03-2019 08:17 PM I use a neat program for finding extremums by solving to find when d/dx=0. The derivative program goes like this LBL "DX" MVAR "X" MVAR "H" RCL "X" RCL "H" COMPLEX XEQ "FX" COMPLEX END This works in solve for most routine functions ("FX"). I am having a problem with a more complicated function, where the program for the function ("FX") executes successfully, but my derivative function ("DX") will not work in solve (generates an "invalid type" error). An example is the following program "(FX") which executes successfully, but not in the solver in program "DX" LBL "FX" ENTER ENTER ENTER X^2 5 - X<0? +/- SQRT END Is there a way to handle this sort of thing where the DX program can work in solve? RE: HP 42S Question - lrdheat - 02-03-2019 08:18 PM "H" is some small epsilon such as 1E-5 RE: HP 42S Question - Thomas Okken - 02-03-2019 09:38 PM The X<0? function doesn't work on complex numbers. That's what's causing the Invalid Type error message. This makes sense because the complex numbers are not an ordered set, unlike the reals. None of the inequality tests work with them, but X=Y? and X≠Y? do. N.B. Those tests do exhibit some behavior that might be surprising and mathematically questionable, specifically, they consider x and x+0i to be not equal. In the case of real numbers, the sequence X<0? +/- is equivalent to ABS, but if you want this to work with complex numbers, you should replace it with the actual ABS function, if you want the square root of the magnitude of the number, or leave it out, since SQRT works on all complex numbers. RE: HP 42S Question - lrdheat - 02-03-2019 10:02 PM I had utilized the ABS function initially, it didn't work in "DX" as it is written, which is why I resorted to X<0?, +/-. I had been getting the same invalid error statement. I'm flummoxed at this point (my skill level, admittedly pedestrian). RE: HP 42S Question - Thomas Okken - 02-03-2019 10:11 PM If simply taking the square root is not an option, i.e. you want to force the real part of the complex number to be nonnegative, you could do this: COMPLEX RCL ST Y SIGN STO× ST Z × COMPLEX RE: HP 42S Question - Thomas Klemm - 02-04-2019 05:47 AM (02-03-2019 10:11 PM)Thomas Okken Wrote: If simply taking the square root is not an option, i.e. you want to force the real part of the complex number to be nonnegative, you could do this: (08-25-2018 08:00 PM)Thomas Klemm Wrote: Unfortunately \(x=\Re[z]\) and \(y=\Im[z]\) aren't analytic functions. So anything based on these values isn't analytic as well. In your case I'd rather separate the functions: \(f(z)=\sqrt{z^2-5}\) \(g(z)=\sqrt{5-z^2}\) What is your "more complicated function"? Cheers Thomas RE: HP 42S Question - lrdheat - 02-04-2019 03:07 PM Thanks, Thomas. That was the more complicated function! Functions without absolute values or odd numbered nroots and such mostly work fine in "FX" and then in "DX". RE: HP 42S Question - SammysHP - 02-04-2019 05:39 PM Some background for the complex step differentiation and its limitations: https://blogs.mathworks.com/cleve/2013/10/14/complex-step-differentiation/ RE: HP 42S Question - lrdheat - 02-05-2019 06:15 AM Thanks for the blog. |