Post Reply 
HP 42S Question
02-03-2019, 08:17 PM
Post: #1
HP 42S Question
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?
Find all posts by this user
Quote this message in a reply
02-03-2019, 08:18 PM
Post: #2
RE: HP 42S Question
"H" is some small epsilon such as 1E-5
Find all posts by this user
Quote this message in a reply
02-03-2019, 09:38 PM (This post was last modified: 02-03-2019 10:14 PM by Thomas Okken.)
Post: #3
RE: HP 42S Question
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.
Visit this user's website Find all posts by this user
Quote this message in a reply
02-03-2019, 10:02 PM
Post: #4
RE: HP 42S Question
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).
Find all posts by this user
Quote this message in a reply
02-03-2019, 10:11 PM
Post: #5
RE: HP 42S Question
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
Visit this user's website Find all posts by this user
Quote this message in a reply
02-04-2019, 05:47 AM
Post: #6
RE: HP 42S Question
(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:

COMPLEX
RCL ST Y
SIGN
STO× ST Z
×
COMPLEX

(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.

Quote:Just add the check straight into Fx

This violates the precondition of this algorithm: the function must be analytical

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
Find all posts by this user
Quote this message in a reply
02-04-2019, 03:07 PM
Post: #7
RE: HP 42S Question
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".
Find all posts by this user
Quote this message in a reply
02-04-2019, 05:39 PM
Post: #8
RE: HP 42S Question
Some background for the complex step differentiation and its limitations: https://blogs.mathworks.com/cleve/2013/1...entiation/
Visit this user's website Find all posts by this user
Quote this message in a reply
02-05-2019, 06:15 AM
Post: #9
RE: HP 42S Question
Thanks for the blog.
Find all posts by this user
Quote this message in a reply
Post Reply 




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