Showing posts with label Thomas Oakken. Show all posts
Showing posts with label Thomas Oakken. Show all posts

Saturday, August 20, 2022

Plus42: The Solver SEQ Command

Plus42: The Solver SEQ Command


Solver SEQ Function


In the calculator app Plus42, we can evaluate a sequence of calculations to return a result.  The SEQ is also good for the FOR loop because it allows us to initialize several variables.


Syntax:

SEQ( expr1 : expr2 : expr3: ... : expr_n )


I think this is best illustrated by example.


Example 1


Calculate   f(x) = x * p ÷ t^2


where:

p = 0.01 * a^2

a = 36 *t^2 - 280


Equation:

SEQ1:F=SEQ(L(A:36×T^2-280):L(P:.01×G(A)^2))×X÷EXP(T)


The commands listed in the SEQ are:


1.  L(A:36×T^2-280):  Let A = 36 * T^2 - 280.  T is the input variable.  


2.  L(P:.01×G(A)^2)):  Let P = 0.01 * A^2;  the Get command (G) is used to keep A from the variable menu


The answer is stored in P.


Variables in calculation:  F, T, X


X = 2, T = 0.8, solve for F = 593.3698253


X = 0.3, T = 9, solve for F = 2.57253759


T = 11.1, F = 58.68, solve for X = 22.4853545434


Example 2


Calculate p = Π( n / 4, n = 1 to m)


Equation:

SEQ2: P=FOR(SEQ(L(A:1):L(N:1)):G(N)<=IP(M):L(N:G(N)+1):L(A:G(A)×(G(N)÷4)))


The commands listed in the SEQ are:


1.  L(A:1):   Let A = 1


2.  L(N:1):  Let N = 1


In this example, SEQ is in a FOR command and is used to initialize variables.   


Variables in calculation: M, P


M = 3, solve for P = 0.09375


M = 6, solve for P = 0.17578125


M = 18, solve for P = 93166.79943


If you have not checked out the Plus42 app, please check it out.  The Plus42 is an HP-42S Simulator which builds up on the Free42.   However, the Plus42 adds the solver in a style of the HP 17B and 27S, graphing commands, and units.


Thomas Okken's Plus42 page:  https://www.thomasokken.com/plus42/


Note:  Casio fx-991EX Week - September 5, 2022 to September 9, 2022 


All original content copyright, © 2011-2022.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 

Saturday, July 9, 2016

HP 42S Programming Part I: Matrix Column Sum, GCD, Error Function

HP 42S Programming Part I:  Matrix Column Sum, GCD, Error Function

Continuing with calculators from the 1980s, this series will present one of the most beloved scientific calculators and one of the most sought after: the Hewlett Packard HP 42S from the late 1980s.  If you want one, you might want to save up because HP 42S calculators are valuable, and often cost over $100.

It is one of my most favorite calculators of all time. 

Free42

However, you can use an emulator for the HP 42S for free, check out the Free42 by Thomas Oakken.  It is a rewrite of the HP 42S code and the emulator is available on many platforms including Widows, Mac, iOS, and Android.  Link:  http://thomasokken.com/free42/   

Oakken accepts donations.





Part III hopefully to come next week.  

As usual, anything that comes after the double-backslash is a comment only.

HP 42S: Column Sums of a Matrix

This could potentially had been a medium to long sized programs involving loops, but thanks to the powerful function RSUM (found in CATALOG-FUNC or executed by XEQ RSUM) this program will be quite short.  RSUM is the row sum function, or the sum of each row of a matrix.

Just put a matrix on the stack and run CSUM.  When the program is finished, press [shift] [ 9 ] (MATRIX), {EDIT} to see the sums.

00 {12-Byte Prgm}
01 LBL “CSUM”
02 TRANS \\ transpose
03 RSUM
04 END

Test:  MAT1 = [ [4, 3, 1], [5, 8, 2], [7, 6, 3]]
Result:  [16, 17, 6]

HP 42S:  GCD (Greatest Common Divisor) by Euclid Division

Enter the two integers on the Y stack and X stack.  Order doesn’t matter.

00 {42-Byte Prgm}
01 LBL “GCD”
02 X<Y?
03 X<>Y
04 STO 01  \\ store maximum in R01
05 X<>Y
06 STO 00  \\ store minimum in R00
07 LBL 00 \\ main loop
08 RCL 01
09 ENTER
10 RCL÷ 00
11 IP
12 RCL* 00
13 –
14 X=0?  \\ is max – IP(min/max)*min = 0?
15 GTO 01
16 X<>Y
17 STO 01
18 X<>Y
19 STO 00
20 GTO 00
21 LBL 01 \\ display GCD
22 RCL 00
23 “GCD:”
24 ARCL ST X
25 AVIEW
26 END


Test:   Find the GCD of 485 and 175.
485 [ENTER] 175 [XEQ] {GCD}   Result:  5
Alternatively:
175 [ENTER] 485 [XEQ] {GCD}   Result:  5


HP 42S:  Error (erf) Function


ERF(X) = ∫ 2/√π * (e^(-T^2)) dT, from T = 0 to T = x

Integrand:
00 {22-Byte Prgm}
01 LBL “ERF”
02 MVAR “T”
03 RCL “T”
04 X^2
05 +/-
06 E^X
07 2
08 *
09 PI
10 SQRT
11 ÷
12 END

Instructions:

Press [(shift)] [ 8 ] (∫ f(x) )
Choose ERF at the “Select ∫f(x) Program”
Select T at Set Vars; Select ∫var
Store 0 in LLIM, X in ULIM, a suitable accuracy factor (10^-n) in ACC
Press the ∫ soft key.

Test: erf(1.2) with ACC of 1E-6  (LLIM = 0, ULIM = 1.2) 
Result:  0.9103


 This blog is property of Edward Shore, 2016.

RPN HP 12C: Fibonacci and Lucas Sequences

  RPN HP 12C: Fibonacci and Lucas Sequences Golden Ratio, Formulas, and Sequences Let φ be the Golden Ratio: φ = (1 + √5) ÷ 2...