Post Reply 
(28/48/50) Dual Number Functions
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
  f
    \<< 2 OVER * 3 + OVER DMUL 5 + DMUL 7 +
    \>>
  NEWTON
    \<< 1 R\->C \-> x
      \<< x f C\->R / x C\->R DROP SWAP -
      \>>
    \>>
  CST { { "SINH" { DSINH DASNH } } { "COSH" { DCOSH DACSH } } { "TANH" { DTANH DATNH } } { "R\->P" DR\->P } { "P\->R" DP\->R } { "R\->C" { R\->C DC\->R } } }
  KEYS { S DSIN 41.1 DASIN 41.2 DCOS 42.1 DACOS 42.2 DTAN 43.1 DATAN 43.2 DSQRT 44.1 DSQ 44.2 DNROOT 44.3 DDPWR 45.1 DIPWR 45.2 DARG 45.3 DINV 46.1 DEXP 46.2 DLN 46.3 DDIV 65.1 DMUL 75.1 }
  DSIN
    \<< DC\->R OVER COS * SWAP SIN SWAP R\->C
    \>>
  DASIN
    \<< DC\->R SWAP ASIN SWAP OVER COS / R\->C
    \>>
  DCOS
    \<< DC\->R OVER SIN NEG * SWAP COS SWAP R\->C
    \>>
  DACOS
    \<< DC\->R SWAP ACOS SWAP OVER SIN / R\->C
    \>>
  DTAN
    \<< DC\->R SWAP TAN SWAP OVER SQ 1 + * R\->C
    \>>
  DATAN
    \<< DC\->R OVER ATAN ROT ROT SWAP SQ 1 + / R\->C
    \>>
  DSINH
    \<< DC\->R OVER SINH ROT ROT SWAP COSH * R\->C
    \>>
  DASNH
    \<< DC\->R SWAP ASINH SWAP OVER COSH / R\->C
    \>>
  DCOSH
    \<< DC\->R OVER COSH ROT ROT SWAP SINH * R\->C
    \>>
  DACSH
    \<< DC\->R SWAP ACOSH SWAP OVER SINH / R\->C
    \>>
  DTANH
    \<< DC\->R SWAP TANH SWAP OVER SQ 1 SWAP - * R\->C
    \>>
  DATNH
    \<< DC\->R OVER ATANH ROT ROT SWAP SQ 1 SWAP - / R\->C
    \>>
  DARG
    \<< DC\->R SWAP /
    \>>
  DR\->P
    \<< DC\->R OVER / R\->C
    \>>
  DP\->R
    \<< DC\->R OVER SWAP * R\->C
    \>>
  DINV
    \<< DC\->R OVER INV ROT ROT NEG SWAP SQ / R\->C
    \>>
  DMUL
    \<< DC\->R ROT DC\->R OVER 5 PICK * 5 ROLLD ROT ROT * ROT ROT * + R\->C
    \>>
  DDIV
    \<< DC\->R ROT DC\->R 4 PICK * OVER 4 ROLL * - SWAP 3 PICK / ROT ROT SWAP SQ / R\->C
    \>>
  DSQ
    \<< DC\->R OVER SQ ROT ROT * 2 * R\->C
    \>>
  DSQRT
    \<< DC\->R SWAP \v/ SWAP OVER 2 * / R\->C
    \>>
  DLN
    \<< DC\->R OVER / SWAP LN SWAP R\->C
    \>>
  DEXP
    \<< DC\->R SWAP EXP SWAP OVER * R\->C
    \>>
  DIPWR
    \<< SWAP DC\->R OVER 4 PICK ^ 4 ROLLD SWAP 3 PICK 1 - ^ * * R\->C
    \>>
  DDPWR
    \<< DC\->R ROT DC\->R OVER 5 PICK ^ 5 ROLLD OVER 5 ROLL SWAP OVER 1 - ^ * * SWAP LN ROT * 3 PICK * + R\->C
    \>>
  DNROOT
    \<< SWAP DC\->R OVER 4 PICK INV ^ 4 ROLLD SWAP ABS 3 PICK INV 1 - ^ * SWAP / R\->C
    \>>
  DC\->R
    \<< DUP TYPE 1 SAME
      \<< C\->R
      \>> 0 IFTE
    \>>
END

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:
\<< 
  2 OVER *
  3 + OVER DMUL
  5 + DMUL
  7 +
\>>

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:
\<<
  1 R\->C \-> x
  \<<
    x f C\->R /
    x C\->R
    DROP SWAP -
  \>>
\>>

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
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (28/48/50) Dual Number Functions - Gil - 02-20-2024, 10:17 AM
RE: (28/48/50) Dual Number Functions - Gil - 02-21-2024, 12:57 AM
RE: (28/48/50) Dual Number Functions - Thomas Klemm - 02-21-2024 04:34 AM
RE: (28/48/50) Dual Number Functions - Gil - 02-21-2024, 04:49 AM
RE: (28/48/50) Dual Number Functions - Gil - 02-21-2024, 04:47 PM



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