Edward Shore, HHC 2017 September 2017

Slides:



Advertisements
Similar presentations
Maths & Trig, Statistical functions. ABS Returns the absolute value of a number The absolute value of a number is the number without its sign Syntax ◦
Advertisements

Types and Arithmetic Operators
Unit 3: Lesson 1: 3.1 Polynomial Basics (4-1)
Mathematics of Cryptography Part I: Modular Arithmetic
Agenda  Commenting  Inputting Data from Keyboard (scanf)  Arithmetic Operators  ( ) * / + - %  Order of Operations  Mixing Different Numeric Data.
Review Topics (Ch R & 1 in College Algebra Book) Exponents & Radical Expressions (P and P ) Complex Numbers (P. 109 – 114) Factoring (p.
Number systems, Operations, and Codes
By Kendal Agbanlog 6.1-Measurement Formulas and Monomials 6.2-Multiplying and Dividing Monomials 6.3-Adding and Subtracting Polynomials 6.4-Multiplying.
Hungarian Notation A must in this course Every object used MUST be renamed including the form(s) using the following rules Form  frmFormName E.g. frmTemperature.
Introduction To Number Systems Binary System M. AL-Towaileb1.
Objectives: Students will be able to… Determine the number of zeros of a polynomial function Find ALL solutions to a polynomial function Write a polynomial.
WARM UP 1. Sketch the graph of y = tan θ 2. What transformation of function f is represented by g(x) = 3 f(x)? 3. Write the general equation of a quadratic.
William Stallings Computer Organization and Architecture 8th Edition
CHAPTER 5: Representing Numerical Data
Bitwise Operations C includes operators that permit working with the bit-level representation of a value. You can: - shift the bits of a value to the left.
Variables, Operators, and Expressions
CS 106A, Lecture 4 Introduction to Java
Today Variable declaration Mathematical Operators Input and Output Lab
The Little man computer
ALGORITHMS AND FLOWCHARTS
Topics Designing a Program Input, Processing, and Output
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
OBJECT ORIENTED PROGRAMMING II LECTURE 23 GEORGE KOUTSOGIANNAKIS
BASIC ELEMENTS OF A COMPUTER PROGRAM
Digital Logic & Design Dr. Waseem Ikram Lecture 02.
04 Evaluate nth Roots and Use Rational Exponents
Completing the Problem-Solving Process
3.1 Polynomial Functions and their Graphs
Dr. Clincy Professor of CS
Instructor: David Ferry
BYTE AND STRING MANIPULATON
Primitive Data, Variables, Loops (Maybe)
The Selection Structure
Intro to C Tutorial 4: Arithmetic and Logical expressions
CHAPTER 4: Representing Integer Data
Lecture 16 Arithmetic Circuits
William Stallings Computer Organization and Architecture 7th Edition
Digital Systems Section 14 Registers. Digital Systems Section 14 Registers.
PROGRAMME F1 ARITHMETIC.
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Defining Types of data expression Dn [name] expression Dn [name]
Arithmetic operations, decisions and looping
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Final Exam Review Department of Electrical and Computer Engineering
Fundamentals of Programming I Number Systems
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
Digital Logic & Design Lecture 02.
ECEG-3202 Computer Architecture and Organization
Problems, understanding and solutions
CPS120: Introduction to Computer Science
Topics Designing a Program Input, Processing, and Output
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
CS150 Introduction to Computer Science 1
Chapter 8 Computer Arithmetic
CS150 Introduction to Computer Science 1
Topics Designing a Program Input, Processing, and Output
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Topics Designing a Program Input, Processing, and Output
AS-Level Maths: Core 2 for Edexcel
Number Systems.
Finding Equations of Exponential Function
SPONGE (3x + 2)4 (2x – 5y)3.
Computer Organization and Assembly Language
Chapter 10 Instruction Sets: Characteristics and Functions
Presentation transcript:

Edward Shore, HHC 2017 September 2017 Expanding the HP 12C Edward Shore, HHC 2017 September 2017

Objectives To expand the HP 12C beyond the basic and financial capabilities Mathematical Tips and Tricks for the HP 12C Applications

Assumptions The regular/classic version of the HP 12C is used instead of the Platinum Edition 99 programming steps vs. 400 programming steps Always RPN vs. RPN/ALG setting Two digit vs. Three digit step markers LST X Code (43, 36 vs. 43, 40) No trigonometric functions are used Fix 2 Mode (round everything to 2 decimal places) is set

Other Sources Polynomial Solver Polynomials: Valentin Abillo http://www.hpcc.org/datafile/V21N2/V21N2P35.pdf Trig Functions Trigonometric Functions: Valentin Abillo http://www.hpcc.org/datafile/hp12/12c_TrigonometryFunctions.pdf

Quick Mathematical Tips

Arithmetic Multiplying by 100: [ENTER], 1, [x<>y], [%T] One key stroke less than [ENTER], 1, 0, 0, [ * ] Dividing by 100: [ENTER], 1, [ % ] Two key strokes less than [ENTER], 1, 0, 0, [ ÷ ]

Mathematical Functions Absolute Value: 2, [y^x], [ g ] ( √ ) Sign Function: [ENTER], [ENTER], 2, [y^x], [ g ] ( √ ), [ ÷ ] Modulus of two positive numbers (a mod b): a, [ENTER], b, [ ÷ ], [ g ] (LSTx), [ x<>y ], [ g ] (FRAC), [ * ]

Mathematical Functions Number of Digits of an integer: [ g ] (LN), [EEX], 1, [ g ] (LN), [ ÷ ], [ g ] (INTG), 1, [ + ]

Keying in π The HP 12C does not have a π button, we’ll have to enter π manually or use an approximation. Using the 10 digit approximation 3.1415965359. This will take 11 steps, one for each digit and the decimal point. We can use the approximation π ≈ 355/113. 355/113 = 3.14159292035 (to 5 decimal places) This takes 8 steps: 3, 5, 5, ENTER, 1, 1, 3, ÷ Richard Nelson suggests this memory aid: take the first three odd digits twice (113355), divide last three by first three (355/113).

Example: Surface Area & Volume of Sphere Step Code Key Notes 01 44, 0 STO 0 Store radius in R0 02 2 Calculate surface volume 03 21 Y^X   04 4 05 20 * 06 3 Enter π 07 5 08 09 36 ENTER 10 1 11 12 13 ÷ 14 15 31 R/S Display surface volume 16 Calculate volume 17 18 45, 0 RCL 0 19 43, 33, 00 GTO 00 Display volume, stop program execution

Number of Inputs Three ways to generate inputs: Loading the stack before executing the program. This is useful when you have only one input. Prompt for the inputs using the [R/S]. Store all the required inputs in the registers before execution. This is my preferred method when I have 3 or more inputs.

Using x=0 to determine choices You can designate a memory register, such as R0, as a choice variable. For example: Choice 0 executes function f(x) Choice 1 executes function g(x) And so on Depending on program size, 2 to 4 choices could fit within program memory. General algorithm: RCL R#, test value, -, x=0, GTO appropriate line number

Example – Choices: US to SI Unit Conversion Step Code Key Notes 01 44, 0 STO 0 Store choice variable in R0 02 34 X<>Y   03 44, 1 STO 1 Store value to be converted in R1 04 05 43, 35 X=0 Conversion: lb to kg? 06 43, 33, 18 GTO 18 07 45, 0 RCL 0 Conversion: in to cm? 08 1 09 30 - 10 X=0? 11 43, 33, 27 GTO 27 12 Conversion: gal to L? 13 2 14 15 16 43, 33, 34 GTO 34 17 43, 33, 43 GTO 43 Conversion: mi to km? 18 45, 1 RCL 1 Conversion: lb to kg, flag = 0 19 20 48 .

Example – Choices: US to SI Unit Conversion Step Code Key Notes 21 2   22 23 4 24 6 25 10 ÷ 26 43, 33, 00 GTO 00 27 45, 1 RCL 1 Conversion: in to cm, flag = 1 28 29 48 . 30 5 31 32 20 * 33 34 Conversion: gal to L, flag = 2 35 3 36 37 7 38 8 39 40

Example – Choices: US to SI Unit Conversion Step Code Key Notes 41 20 *   42 43, 33, 00 GTO 00 43 45, 1 RCL 1 Conversion: mi to km, flag = 3 44 1 45 48 . 46 6 47 9 49 3 50 51

Use of Statistics Variables We can use stat variables for additional analysis The cost is that six variables will be used (R1 to R6). This leaves only four variables for inputs and outputs (R0, R7, R8, R9) Statistics Variables R1: n R4: Σy R2: Σx R5: Σy^2 R3: Σx^2 R6: Σxy

Example – Simple Logistic Curve Fitting This program uses the statistics variables, particularly Σx for R2 Curve: y = 1 / (A + B*e^(-x)) Transformation: X’ = e^(-X), Y’ = 1/Y

Example – Simple Logistic Curve Fitting Step Code Key Notes 01 16 CHS Enter data 02 43, 22 e^x Adjust X: e^-x 03 34 x<>y   04 22 1/x Adjust Y: 1/y 05 06 49 Σ+ Enter data point, n is displayed 07 43, 33, 00 GTO 00 Stop program execution 08 Calculate b 09 43, 2 y^ 10 44, 7 STO 7 11 31 R/S Display b 12 1 Calculate m 13 14 15 33 R↓ 17 30 - 18 44, 8 STO 8 19 Display m

Simulating Subroutines The HP 12C does not have subroutine commands, but you can simulate subroutines. Here is one way to do it, if you know the subroutine will be used twice: It is very important you plan your program in advance, with line numbers. Marking the line numbers will facilitate where the subroutine and return markings will be located.  

Simulating Subroutines Designate a register as a flag variable. Store 1 in the flag variable. Enter the main portion of the program. Determine where the subroutine will be called. Follow the subroutine call with the roll down command (R↓). At the end of the subroutine, recall the flag variable. Determine which round it is by recalling the flag variable. First round: flag = 1. Second round: flag = 0. Use the test x=0. If it passes, send the pointer to the second R↓. If it fails, subtract 1 from the flag variable and send the pointer to the first R↓.  

Subroutine Example: Derivative Approximation Step Key Code Notes 01 44, 0 STO 0 Store x in R0 02 1   03 44, 3 STO 3 Set up flag variable, 2 subroutine rounds 04 05 26 EEX 06 5 07 16 CHS 08 44, 1 STO 1 Store h in R1 09 45, 0 RCL 0 10 45, 1 RCL 1 11 40 + x+ h 12 43, 33, 23 GTO 23 Subroutine: 1st round 13 33 R↓ Return: 1st round 14 44, 2 STO 2 Store temp result, f(x + h) 15 x Subroutine: 2nd round 17 18 44, 30, 2 STO- 2 f(x+h) – f(x) 19 45, 2 RCL 2 20

Subroutine Example: Derivative Approximation Step Key Code Notes 21 10 ÷ (f(x+h) – f(x))/h 22 43, 33, 00 GTO 00 Stop execution 23 36 ENTER Subroutine begins here, f(x) 24   25 2 26 Y^X 27 34 X<>Y 28 43, 22 e^x 29 20 * End of f(x) 30 45, 3 RCL 3 Need the next 7 steps to the end of f(x) – Check flag variable 31 43, 35 X=0 32 43, 33, 17 GTO 17 Are we in round 2? 33 1 If yes, go to 2nd return point 44, 30, 3 STO- 3 Otherwise, decrease flag variable 35 R↓ Set up display 43, 33, 13 GTO 13 Go to 1st return point

Additional Examples

Quadratic Equation Step Code Key Notes 01 45, 2 RCL 2 Start with values stored in R1, R2, R3. Calculate discriminant. 02 36 ENTER   03 20 * 04 45, 1 RCL 1 05 45, 3 RCL 3 06 07 4 08 09 30 - 10 44, 0 STO 0 11 31 R/S Display discriminant which is stored in R0. 12 13 43, 34 X≤Y Is 0 ≤ R0? 14 43, 33, 32 GTO 32 If so, go to step 32. 15 Complex Roots: real part 16 17 40 + 18 19 CHS

Quadratic Equation Step Code Key Notes 20 34 X<>Y 21 10 ÷ 22   21 10 ÷ 22 44, 4 STO 4 23 31 R/S 24 43, 36 LSTx Complex Roots: imaginary part 25 45, 0 RCL 0 26 16 CHS 27 43, 21 √ 28 29 30 44, 5 STO 5 43, 33, 00 GTO 00 Stop execution 32 45, 2 RCL 2 Real root calculations 33 35 36 40 + 37 45, 1 RCL 1 38 ENTER 39

Quadratic Equation Step Code Key Notes 40 10 ÷ 41 44, 4 STO 4 42 31   41 44, 4 STO 4 42 31 R/S Real root 1 43 43, 36 LSTx 44 45, 2 RCL 2 45 45, 0 RCL 0 46 43, 21 √ 47 + 48 16 CHS 49 34 X<>Y 50 51 44, 5 STO 5 52 43, 33, 00 GTO 00 Real root 2

Greatest Common Divisor Step Code Key Notes 01 43, 34 X≤Y Determine which integer is greater 02 34 X<>Y 03 44, 1 STO 1 R1 = max(X,Y) 04 05 44, 0 STO 0 R0 = min(X,Y) 06 45, 1 RCL 1 Begin Euclidian division routine 07 Recall R1 twice 08 45, 0 RCL 0 09 10 ÷ Divide R1 by R0 43, 25 INTG int(R1/R0) 11 12 20 * 13 30 - Calculate remainder: remainder = int(R1/R0) * R0 – R1 14 43, 35 X=0 Is remainder = 0? 15 43, 33, 21 GTO 21 If yes, go to the end 16 If not, set up for the next loop 17 Old min becomes new max, R0 → R1

Greatest Common Divisor Step Code Key Notes 18 34 X<>Y 19 44, 0 STO 0 Store new min 20 43, 33, 06 GTO 06 Start Euclidian division routine again 21 45, 0 RCL 0 End Result: display GCD 22 43, 33, 00 GTO 00 Stop execution

Binary to Decimal Conversion Step Code Key Notes 01 44, 0 STO 0 Store the binary integer, assume no sign bit 02 43, 23 LN Determine the number of digits 03 26 EEX   04 1 05 06 10 ÷ 07 43, 25 INT 08 09 40 + 44, 2 STO 2 Store number of digits in R2 11 Initialize decimal conversion, store 0 in R1 12 44, 1 STO 1 13 44, 3 STO 3 14 45, 0 RCL 0 Conversion process 15 45, 3 RCL 3 16 17 18 19

Binary to Decimal Conversion Step Code Key Notes 20 34 X<>Y   21 Y^X 22 10 ÷ 23 43, 24 FRAC 24 26 EEX 25 1 * 27 43, 25 INTG 28 2 29 36 ENTER 30 45, 3 RCL 3 31 32 33 44, 40, 1 STO+ 1 35 44, 40, 3 STO+ 3 Determine the number of digits left to work with

Binary to Decimal Conversion Step Code Key Notes 37 45, 2 RCL 2   38 30 - 39 43, 35 X=0 40 43, 33, 42 GTO 42 41 43, 33, 14 GTO 14 42 45, 1 RCL 1 Display decimal integer 43 43, 33, 00 GTO 00

Thank you! Any questions?