(28/48/50) Dual Number Functions
|
02-19-2024, 08:37 PM
Post: #1
|
|||
|
|||
(28/48/50) Dual Number Functions
The programs listed here provide functions for calculations with dual numbers, which are similar to complex numbers but instead of the imaginary unit i they use the infinitesimal unit ε. The programs are mostly simple translations of functions in Thomas Klemm's HP42S program here and in Ángel Martin’s Double ROM.
These programs use complex numbers as a convenient stand-in for dual numbers but these numbers are not actually complex numbers, and mixing the two will most likely yield nonsense results. However, the operations of addition, subtraction and negation are the same as for complex numbers, and the absolute value of a dual number is just the real part. Thus there are no programs for these functions. The first listing is a directory of programs providing arithmetic and transcendental functions, as well as the program DC→R which is a modification of C→R which accepts either real or complex numbers. This is to allow easy mixing of dual numbers and real numbers, which are interpreted as (x, 0). Code:
The next listing is the same directory optimized for the HP 49/50 using newer stack commands and decimal points for real numbers. Code:
Next we have a directory of trig functions including hyperbolic functions, arg and rectangular/polar conversions. They require the command DC→R from the directory above, so that command should be added to this directory if it is not in your path. Code:
Finally, the same directory optimized for the 49/50. Code:
|
|||
02-20-2024, 10:17 AM
(This post was last modified: 02-20-2024 10:27 AM by Gil.)
Post: #2
|
|||
|
|||
RE: (28/48/50) Dual Number Functions
Very nice and good examples of how to play with User RPN.
And welcome, as new HP50G programs seem not to have (any more?) the real favour of the HP community. Regards, Gil |
|||
02-20-2024, 09:23 PM
Post: #3
|
|||
|
|||
RE: (28/48/50) Dual Number Functions
(02-20-2024 10:17 AM)Gil Wrote: Very nice and good examples of how to play with User RPN. Actually they should be rewritten in SysRPL both for improved accuracy using extended reals, and for faster and easier type checking so as to allow exact integer and symbolic versions on the 49 and 50. Unfortunately my SysRPL skills are remedial at best and that is unlikely to happen unless a more competent person wants to volunteer. |
|||
02-21-2024, 12:57 AM
Post: #4
|
|||
|
|||
RE: (28/48/50) Dual Number Functions
As it is now it's most understandable for me and suits me better that way.
|
|||
02-21-2024, 04:34 AM
Post: #5
|
|||
|
|||
RE: (28/48/50) Dual Number Functions
It took me a while to figure out how to transfer these programs to the iHP48 app.
For this I used the programs IN and OUT that I found in BruceH's post: #2 I copied them, double tapped the screen and used: EDIT → Paste into iHP Stack Then I manually replaced the trigrams in the string of IN and used OBJ→ to create the program. This allowed me to use IN to transform OUT. But you can just as well use these two directly. IN: Code: « →STR 3 TRANSIO RCLF SIZE 3 > # 193357d # 196971d IFTE SYSEVAL + STR→ » OUT: Code: « STD 64 STWS →STR 3 TRANSIO RCLF SIZE 3 > # 193359d # 196297d IFTE SYSEVAL » Once transferred I moved all programs into a single directory DUAL and created both a CST menu and key assignments in KEYS: Code: DIR Once the directory object has been copied over and translated by IN just save it in a variable say DUAL. This will create the directory with all the files. The contents of KEYS can then be stored using STOKEYS. Then hit USER twice to activate the assignments permanently. Use CST to activate the customer menu. Examples: Arithmetic \( (3 + 4\varepsilon)(5 + 6\varepsilon) \) 3 4 R→C 5 6 R→C * (15,38) Evaluation of a function and its derivative \( \begin{align} f(x) = \frac{1}{\sqrt{3 + \sin(x)}} \end{align} \) Evaluate \(f(2)\) and \(f'(2)\). 2 1 R→C SIN 3 + √ INV (0.505767179164,2.69195956021E-2) Polynomial Write a program to evaluate the following polynomial: \( f(x) = 2x^3 + 3x^2 + 5x + 7 \) Code: \<< Hint: Please note the use of the ordinary multiplication × with a constant. Finding a root with Newton's algorithm \( \begin{align} x \mapsto x - \frac{f(x)}{f'(x)} \end{align} \) The program is straight forward since both the function and its derivative can be calculated with a single call to f: Code: \<< Now we can use it to find the root of the previous polynomial: -1 NEWTON NEWTON NEWTON … -1.6 -1.4594795539 -1.44565202879 -1.44552846845 -1.44552845868 -1.44552845868 |
|||
02-21-2024, 04:49 AM
Post: #6
|
|||
|
|||
RE: (28/48/50) Dual Number Functions
The following precious program INOUT was once given to me by one of the HP Museum member:
Code: \<< RCWS RCLF \-> ws f |
|||
02-21-2024, 05:56 AM
Post: #7
|
|||
|
|||
RE: (28/48/50) Dual Number Functions
(02-21-2024 04:49 AM)Gil Wrote: The following precious program INOUT was once given to me by one of the HP Museum member: It's from post #4 by user grsbanks in the same thread I linked earlier. |
|||
02-21-2024, 04:34 PM
Post: #8
|
|||
|
|||
RE: (28/48/50) Dual Number Functions
(02-20-2024 10:17 AM)Gil Wrote: And welcome, as new HP50G programs seem not to have (any more?) the real favour of the HP community. I don't think this is accurate. It seems to me that there are a handful of vocal members here at the hpmuseum who seem to enjoy disparaging the RPL calculators, and I'd even go so far as to say that there has been some small amount of "chilling effect" regarding participation in RPL-related threads as a result. But I don't believe that should be interpreted as a consensus of the community's appreciation for those systems. Case in point: Eddie Shore recently posted a poll regarding preferred systems for "quick number crunching", and the RPL systems were well-represented in the results. Personally, I find threads like this one intriguing. I just lack the mathematical background to make practical use of the concepts. I'd enjoy participating in an effort to implement these commands in SysRPL, though (time permitting). Certain characteristics of the 49g-50g SysRPL environment are a good fit for this kind of application. In particular, I'd like to better understand the implications of function overloading for exact integers here vs. extended reals. |
|||
02-21-2024, 04:47 PM
Post: #9
|
|||
|
|||
RE: (28/48/50) Dual Number Functions
I meant many RPN programs for calculators, yes, but for other calculators than the HP50G.
Just an impression. Regards |
|||
02-22-2024, 07:13 AM
Post: #10
|
|||
|
|||
RE: (28/48/50) Dual Number Functions
(02-21-2024 04:34 PM)DavidM Wrote: Personally, I find threads like this one intriguing. I just lack the mathematical background to make practical use of the concepts. Consider two resistors with a certain tolerance: \( \begin{align} R_1 &= 3 \pm 4 \varepsilon \\ R_1 &= 5 \pm 6 \varepsilon \\ \end{align} \) What is the total resistance and its tolerance if both resistors are in parallel? 3 4 R→C 1/X 5 6 R→C 1/X + 1/X (1.875,2.40625) Compare this to the calculation if \(\varepsilon = 1e-5\): 3.00004 1/X 5.00006 1/X + 1/X 1.8750240625 With each number we include the linearization of its perturbation. |
|||
03-20-2024, 07:14 PM
(This post was last modified: 03-20-2024 07:16 PM by John Keith.)
Post: #11
|
|||
|
|||
RE: (28/48/50) Dual Number Functions
Next up, dual number elliptic integrals... and a mystery.
The programs DNEK, DNEE, DNEΠ and DNEN compute respectively the dual number versions of K(k), E(k), Π(n, k) and q(k), the elliptic nome. They use the programs from this thread on elliptic integrals. I am also including translations of the programs DAGM and DELK from the Double ROM manual. Ángel Martin’s Double ROM manual has programs for dual number AGM and E(k). The example on p.34 gives a value of -2.622842115+ε*2.858860658 for the input 0.5+ε, whereas with the same input I get the value 1.68575035482+ε*.541731848587 with both DNEK and DELK. Perhaps someone who is an HP-41 user familiar with the Double ROM can check my results and explain the different results. I am listing the program as a directory including all dual number and elliptic integral programs needed to run them. The directory is thus self-contained and can be used with any RPL calculator, although the names of programs for Π(n, k) will have to be changed for the HP-28 due to its character set not having Π. Code:
And a listing optimized for the HP 49 and 50. Code:
|
|||
03-21-2024, 05:13 PM
(This post was last modified: 03-22-2024 07:49 PM by Albert Chan.)
Post: #12
|
|||
|
|||
RE: (28/48/50) Dual Number Functions
(03-20-2024 07:14 PM)John Keith Wrote: Ángel Martin’s Double ROM manual has programs for dual number AGM and E(k). The example on p.34 gives a value of -2.622842115+ε*2.858860658 for the input 0.5+ε, whereas with the same input I get the value 1.68575035482+ε*.541731848587 with both DNEK and DELK. Hi, John Keith Your numbers are correct. lua> D = require'dual'.D lua> k = D.new(0.5, 1) lua> a, b = 1+k, 1-k lua> repeat b0=b[1]; a,b = (a+b):mul(.5), (a*b):sqrt(); until b0==b[1] lua> unpack(b) -- = AGM(a,b) 0.9318083916224482 -0.29944545531661104 lua> K = pi/2 / b lua> unpack(K) -- = K( k=0.5+ε ) 1.685750354812596 0.5417318486132805 With dual numbers, we don't need modified AGM. We can get E from K From https://en.wikipedia.org/wiki/Elliptic_integral (dE/dk) = (E-K)/k (dK/dk) = E/(k*(1-k*k)) - K/k = (dE/dk) / (1-k*k) + K * k/(1-k*k) (dE/dk) = (1-k*k)*(dK/dk) - k*K E = K + k*(dE/dk) lua> E = D.new(0, (1-k[1]*k[1])*K[2] - k[1]*K[1]) lua> E[1] = K[1] + k[1]*E[2] lua> unpack(E) -- = E( k=0.5+ε ) 1.4674622093394272 -0.43657629094633765 |
|||
03-22-2024, 04:23 PM
(This post was last modified: 03-22-2024 07:50 PM by Albert Chan.)
Post: #13
|
|||
|
|||
RE: (28/48/50) Dual Number Functions
It may be simpler to use elliptic parameter m = k^2
Example, here is prove for Legendre's relation using m https://en.wikipedia.org/wiki/Elliptic_integral Wrote:Complete elliptic integral of the second kind, Derivative and differential equation With f' = df/dm, m* = 1-m, above differential equations simplified to: E' = (E-K) / (2 m) E = -4 m* (m E')' = -2 m* (E-K)' -E / (2 m*) = E' - K' K' = (E-K) / (2 m) + E / (2 m*) 2 m m* K' = m* (E-K) + m E = E - m* K = (E-K) + m K (E-K) = 2 m m* K' - m K = (2 m) (m* K' - K/2) E' = m* K' - K/2 E = K + 2 m E' Redo previous post example using m = k^2 lua> D = require'dual'.D lua> m = D.new(0.5^2, 1) lua> a, b = 1, (1-m):sqrt() lua> repeat b0=b[1]; a,b = (a+b):mul(.5), (a*b):sqrt(); until b0==b[1] lua> unpack(b) -- = AGM(a,b) 0.9318083916224482 -0.29944545531661104 lua> K = pi/2 / b lua> unpack(K) -- = K( m=0.25+ε ) 1.685750354812596 0.5417318486132805 lua> E = D.new(0, (1-m[1])*K[2] - K[1]/2) lua> E[1] = K[1] + 2*m[1]*E[2] lua> unpack(E) -- = E( m=0.25+ε ) 1.4674622093394272 -0.43657629094633765 Here, we get same numbers by chance, because dm/dk = 2k = 2*0.5 = 1 |
|||
03-22-2024, 07:04 PM
Post: #14
|
|||
|
|||
RE: (28/48/50) Dual Number Functions
Thanks for confirming my calculations. I was a bit hesitant to question the Double ROM manual and its esteemed author.
I considered using m instead of k, and I may yet reconsider as using m does make some things easier. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)