Showing posts with label linear systems. Show all posts
Showing posts with label linear systems. Show all posts

Saturday, January 11, 2025

RPN with HP 15C & DM32: Solving Simple Systems

RPN with HP 15C & DM32: Solving Simple Systems


Welcome to another edition of RPN with HP 15C & DM32.


Many Approaches to a Solving Problems


This blog covers two ways to solve the simple linear system of two equations:


x + y = a

x – y = b


In matrix form:


[ [ 1, 1 ] [ 1, - 1] ] * [ [ x ] [ y ] ] = [ [ a ] [ b ]


The inverse of the coefficient matrix [ [ 1, 1 ] [ 1, - 1] ]:


[ [ 1, 1 ] [ 1, - 1] ] ^-1 = [ [ 0.5, 0.5 ] [ -0.5, 0.5 ] ]


[ [ x ] [ y ] ] = [ [ 0.5, 0.5 ] [ -0.5, 0.5 ] ] * [ [ a ] [ b ] ]


The solution to the system is:


x = (a + b) / 2

y = (a – b) / 2



As far as keying the solutions in the calculator, we can address this two ways. The first, and probably the easier method, is to use memory registers. The second is to use stack operations such as swap (x<>y), roll up (R↑), roll down (R↓), enter (ENTER) as duplication, and the Last X function (LST x). Both the HP 15C and DM32 use a four-level stack.



The Memory Register Approach


Start with the stack as follows:


Y: a

X: b

The results are presented as:


Y: y

X: x


Memory Registers used:


HP 15C: R1 = a, R2 = b

DM32: A, B


HP 15C Code:


001

42, 21, 11

LBL A

002

44, 2

STO 2

003

34

X<>Y

004

44, 1

STO 1

005

30

-

006

16

CHS

007

2

2

008

10

÷

009

45, 2

RCL 2

010

45, 40, 1

RCL + 1

011

2

2

012

10

÷

013

43, 32

RTN



DM32 Code (31 bytes):


T01 LBL T

T02 STO B

T03 x<>y

T04 STO A

T05 -

T06 +/-

T07 2

T08 ÷

T09 RCL B

T10 RCL + A

T11 2

T12 ÷

T13 RTN


The Stack Approach


Start with the stack as follows:


Y: a

X: b

The results are presented as:


T : original contents of the z stack

Z: original contents of the z stack

Y: y

X: x


This time no memory registers are used


HP 15C Code:


001

42, 21, 12

LBL B

002

40

+

003

43, 36

LST x

004

2

2

005

20

×

006

34

X<>Y

007

36

ENTER

008

33

R↓

009

30

-

010

16

CHS

011

2

2

012

10

÷

013

43, 33

R↑

014

2

2

015

10

÷

016

43, 32

RTN



DM32 Code (24 bytes):


S01 LBL S

S02 +

S03 LAST x

S04 2

S05 ×

S06 x<>y

S07 ENTER

S08 R↓

S09 -

S10 +/-

S11 2

S12 ÷

S13 R↑

S14 2

S15 ÷

S16 RTN



Examples


Example 1:

x + y = 32

x – y = 16


32 ENTER 16 (run program)


Results: y = 8, x = 24


Example 2:

x + y = 9

x – y = -8


Results: y = 8.5, x = 0.5



Until next time,


Eddie


All original content copyright, © 2011-2025. 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, September 7, 2024

HP Prime: Minimum Distance Between a Point and a Line

HP Prime: Minimum Distance Between a Point and a Line



Introduction


We have a line in the form of y = m * x + b, where m is the slope of the line and b is the y-intercept of the line, and a separate point (px, py). The task is to find the minimum distance, or the shortest distance, between the point and the line. The separate point is not required to be on the line. The line and point are in two-dimensional space.


If the point (px, py) is not on the line, then theoretically, there are an infinite amount of distances between the point and the line. However, to get the shortest distance, draw a path that is “directly straight” to the line. This is achieved by choosing a line that connects the (px, py) that is a line that is orthogonal (perpendicular) to the line y = m * x + b.





The line drawn is of the form y = -1/m * x + b1. The slope of the orthogonal line is -1/m. Assuming that m ≠ 0, the y-intercept of the orthogonal line is b1 = y1 + x1 / m.


The next step is to find where the two lines intersect, which is done by solving the following system for x and y:


y = m * x + b

y = -m / n + b1


Label the intersection point (x1, y1). The minimum distance will be calculated as follows:


dist = √( (x1 – px)^2 + (y1 – py)^2 ) = abs( (x1 – px) + (y1 – py)*i)



If m = 0, the line is in the form of y = b. The orthogonal line is x = px, and the distance is simply abs( (y1 – py)*i ).



HP Prime Code: PTLNDIST


EXPORT PTLNDIST()

BEGIN

// 2024-07-21 EWS



// radian

HAngle:=0;



LOCAL px,py,m,b;



INPUT({m,b,px,py},

"Point-Line Distance (px, py), y=mx+b",

{"m:","b:","px:","py:"},

{"m: slope"," b: y-intercept",

"point x","point y"});



LOCAL y0;

y0:=m*px+b;


LOCAL b1,mt,x1,y1,dist,str;

IF m≠0 THEN

b1:=py+px/m;

mt:=[[−m,1],[1/m,1]]^-1*[[b],[b1]];

x1:=mt[1,1];

y1:=mt[2,1];

dist:=ABS((x1-px)+(y1-py)*√(-1));

ELSE

x1:=px;

y1:=b;

dist:=ABS((y1-py)*√(-1));

END;



// print results

PRINT();

PRINT("Results:");

PRINT("Intersect point:");

PRINT("x: "+STRING(x1));

PRINT("y: "+STRING(y1));

PRINT("");



IF m≠0 THEN

str:="Y="+STRING(-1/m)+"*X+"+STRING(b1);

ELSE

str:="X="+STRING(x1);

END;



PRINT("Orthogonal Line:");

PRINT(str);

PRINT("");

PRINT("Minimum Distance:");

PRINT(dist);



RETURN {x1,y1,str,dist};

END;


Note:


√(-1) represents the imaginary number â…ˆ ( [ Shift ], [ 2 ] ).


Inputs:


* The slope of the y-intercept of the line y = m * x + b (no vertical lines, but m can be zero)

* The point (px, py)


Outputs:


* The line that runs through point (px, yx) that is orthogonal to y = m * x + b. The slope and y-intercept of the orthogonal line, which the line will be stated in a string

* The intersection point of the two lines.

* The distance between (px, yx) and the intersection point. (dist)



Examples


Example 1:

Inputs: Line: y = 5 x – 2, Point: (-1, -5)

m = 5

b = -2

px = -1

py = -5


Results:

Intersect point:

x = -0.615384615386

y = -5.07692307692

Orthogonal Line:

Y = -0.2 * X – 5.2

Minimum distance:

0.392232270274



Example 2:

Inputs: Line: y = 6, Point: (3, -9)

m = 0

b = 6

px = 3

py = -9


Results:

Intersect point:

x = 0.764705882353

y = 4.05882352941

Orthogonal Line:

X = 3

Minimum distance:

15



Example 3:

Inputs: Line: y = 4 x + 1, Point: (5, 3)

m = 4

b = 1

px = 5

py = 3


Results:

Intersect point:

x = 0.764705882353

y = 4.05882352941

Orthogonal Line:

Y = -0.25 * X + 4.25

Minimum distance:

4.36564125066


Source

Tremblay, Christopher. Mathematics for Game Developers. Thomson Course Technology. Boston, MA. 2004. ISBN 1-59200-038-X.


Eddie


All original content copyright, © 2011-2024. 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.

Sunday, February 25, 2024

Casio Graphing Calculators: Equation Variables

Casio Graphing Calculators: Equation Variables



Introduction





Most modern Casio graphing calculators have an Equation solver mode that solves linear systems (Simultaneous), polynomials (Polynomial), and general equations.


To find run Equation mode, press [ MENU ] { A }*.


(*Equation mode is currently option A (fx-9750GIII, fx-CG 50, fx-CG 10/20, fx-9860 Slim))



Simultaneous Equations: SimRes and SimCoef




The simultaneous equation mode solves linear systems up to 6 x 6. The coefficients of the equations are stored in the variable Sim Coef (labeled SimCoef in VARS-EQUATION menu) while the results are stored in the variable Sim Result (labeled SimRes).



Polynomials: PlyRes and PlyCoef




The polynomial equation mode solves polynomials with real coefficients up to degree 6 (3 in early graphing models). The coefficients of the polynomial are stored in the variable Poly Coef (labeled PolyCoef in the VARS-EQUATION menu) while the results are stored in the variable Poly Result (labeled PolyRes).



Accessing Equation Variables Outside of Equation Mode





The four equation variables can be recalled by pressing [ VARS ], [ F6 ] { > }, [ EQUA ] { F3 }.


F1: SimRes (S·Rlt on older models)

F2: SimCoef (S·Cof on older models)

F3: PlyRes (P·Rlt on older models)

F4: PlyCof (P·Cof on older models)


The four variables are read-only matrices. We can not store values or information to read-only variables.


If we want to extract specific values from the equations variables, we must store them into a Matrix variable (A – Z, θ). For example, to retrieve the number from the 1st row and column of Sim Coef:


Sim Coef → Mat A

Mat A[1,1]


We can execute operations on equation variables. An interesting check is to run the simultaneous solver of the variable by typing:


Rref Sim Coef


and reading the last column.


Until next time,


Eddie


 All original content copyright, © 2011-2024. 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.




Monday, September 5, 2022

Casio fx-991EX Classwiz Tips: Solving a Linear System

Casio fx-991EX Classwiz Tips:  Solving a Linear System


This week I am going to show some things that can be done with the Casio fx-991EX Classwiz.  


Solving Linear Systems


The Classwiz can solve linear systems.  To enter the Equation mode:

[MENU], [(-)] for A, 1 for Simul Equation


Up to four variables can be solved for. 


One of the nice things of the Classwiz's Equation mode is that the equations as shown as it is written on paper.  


For a 3 x 3 system (with coefficients reset to 0):


0x  + 0y + 0z  = 0

0x  + 0y + 0z  = 0

0x  + 0y + 0z  = 0


with a large left bracket symbol, {, to the left of the equations.


Entering negative numbers will change the plus to minuses:  i.e.  5x - 6y instead of 5x + -6y.  


Use the equals key [ = ] to enter coefficients and call for solutions. 


Example:


- 2x + 11y + 3z = 25 

3x + 6y - 8z = 9

10x + 2y + 9z = -3


x = -1231/1479 ≈ -0.8323191346

y = 3086/1479 ≈ 2.086544963

z = 63/493 ≈ 0.1277890467

 


Eddie


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. 


Sunday, April 21, 2019

App Review: SciPro Math - Campusano (Revisited)

App Review:  SciPro Math - Campusano (Revisited)

The Return of SciPro Math

If you want to see my review of my previous version, please check here:  http://edspi31415.blogspot.com/2018/01/app-review-scipro-math-campusano-apple.html

This review is for the current version (Version 4).  I was emailed by the programmer Roberto A. Campusano when the latest version is now available. 

Quick Facts:

Title:  SciPro Math
Author/Programmer:  Robert A. Campusano
Platform:  iOS
Price: $9.99
Version:  4.0
Website:  https://scipromath.com/







Introduction

The SciPro Math calculator app is a scientific calculator that features over 648 functions that features many applications, including:

*  U.S.-SI Conversions
*  Finance
* Geometry
* Fractions and Proportions
* Solving Linear Systems up to 4 x 4
* Solving Polynomials up the order 4

The SciPro Math has two modes.  If your Apple device (iPhone, iPad, or iPod Touch) is in the portrait position, it is a simple, four function calculator.  If your Apple device  is in the landscape position, it is in the scientific calculator.

The calculator runs in Chain mode.  Therefore, there is no algebraic preferences or parenthesis.  It could get a little used to if you are accustomed to traditional scientific calculators, but not a big deal once get a hang of it.  If you are used to regular four-function calculators, you should feel right at home with the operation of the SciPro Math.

The rest of this review and blog will assume that you are working in scientific calculator mode (landscape). 

The Modifier Toggle Keys

The calculator has five modifier keys:  [ 2nd ], [ 3rd ], [ rad (off), deg (on) ] (4th), [ 5th ], and [ 6th ].  The modifier keys act as toggles, and depending on whether they are turned on and off, determine what keyboard is present.  You can quickly access any keyboard by entering the keyboard's number and pressing the purple [SC] key on top of the app.

I'm going to give details on some of the keyboards later, but information for all the 24 keyboards can be found here:  https://scipromath.com/the-screens/

Think of the modifier keys as "binary powers of 2:"

[2nd] is the 1 flag
[3nd] is the 2 flag
[rad/deg (4th)] is the 4 flag
[5th] is the 8 flag
[6th] is the 16 flag

Any total of flags that exceed 24 shows the 24th keyboard:  Storage Space keyboard.  Here you can access 26 memory registers Av through Zv.

Storing and Calculating

A lot of the keyboards is a dedicated solver for a specific application.  I will go over some of the details later but in general, the keys that belong to a calculation are all grouped by colors. 

In general, in a color group if the key has the format [ var.app ], that is an input variable.  Input the value by typing it, pressing the indigo [ →(X)v ] store button. 

If a key has an equal sign at the end, [ var.app= ], that is an output variable.  Press this button to get the answer. 

Documentation

One of the things that I wasn't crazy about in my previous review was the lack of documentation.  Thankfully, this has greatly improved.

First, the app will give prompts of what each key does.  The prompt will appear in indigo on the upper right hand screen.  I find this super helpful when learning how to use the app. 

Second, the app has its own YouTube channel, SciPro math.  The videos, by Roberto Campusano  explain on how to use some of the applications in a clear, concise fashion.  If you are using this app for the first time, I recommend going over the videos. 

SciPro Math's YouTube channel:  https://www.youtube.com/channel/UCKHZdGBoHBUazE--0CDn4aQ/videos

Some Keyboard Details

Keyboard 0:  Basic Operations - Angles are in Degrees
Modifiers:  None

Variable Registers:  Av, Bv, Cv
Trig Functions:  sin, cos, tan, sci, csi, bta, sihn, cosh, tanh
Functions:  log, ln, 10^x, e^x, x^2, x^3, √, x^1/3, x^-1
Constants:  Ï€, e, Φ

The functions of sci, csi, and bta are specialized. 

Keyboard 1:  Basic Operations - Angles are in Degrees 
Modifiers:  [ 2nd ]

Variable Registers: Dv, Ev, Fv
Trig functions: sec, sec, cot, bsc, bcs, bct, csch, sech, coth
Functions: ln(x+1), x! (x must be an integer), power, roots, log base 2, e^(x-1)
Constants:  γ

Note:  bsc x = 1/sci x,  bct x = 1/csi x, bct x = 1/bta x

Keyboard 2:  Pythagorean Theorem (and Inverse Trig Functions) - Angles are in Degrees

Variable Registers: Gv, Hv, Iv
Inverse Trig Functions: sin^-1, cos^-1,  tan^-1, sinh^-1, cosh^-1, tanh^-1
Constants:  Ï€/2, Ï€/3, Ï€/4, √2, ln 2
Angle Conversions:  r-deg (radians to degrees), d-rad (degrees to radians)

Hypotenuse Function:
x  [hyp] y [ = ] returns √(x^2 + y^2)

Side Function:
x [side] y [ = ] returns √|x^2 - y^x|    ( | n | = abs(n))

Keyboard 3:  Probability
Modifiers: [ 2nd ], [ 3rd ]

Variable Registers: Jv, Kv, Lv
Random Integers:  rand52 (1 -52), rand10 (1 - 10), coin (0 - 1), dice (1 - 6)
x [ x-y ] y [ = ] returns a random integer between x and y.  x and y can be negative

Probability:
x [ xCr ] r [ = ] returns x! / ( (x - r)! * r!): the number of the combinations
x [ xPr ] r [ = ] returns x! / (x - r)!:  the number of permutations

Conversions: between temperatures °F, °C, K

Keyboard 4:  Conversions, Trig in Radians
Modifiers:  [rad/deg] turned to deg

Trig Functions: sci, cos, tan, sci,csi, bta
Conversions: in/mm, in/cm ft/cm, ft/m, yd/m, mi/km, lb/kg

Keyboard 6:  Conversions, Trig in Radians
Modifiers:  [ 3rd ], [ rad/deg ] turned to deg

Trig Functions: sin^-1, cos^-1, tan^-1
Conversions: tsp/Tsp, Tsp/cu, tsp/mL, cu/pt, pt/qt, qt/gal, gal/L

Keyboard 8:  Fractions and Ratios, Slope
Modifiers: [ 5th ]

Two fractions in the form of a/b and c/d
[ a ]:  numerator input of a/b
[ b ]:  denominator input of a/b
[ c ]:  numerator input of c/d
[ d ]: denominator input of c/d

Addition of fractions: Numerator:  [ ad + bc ], Denominator: [ bd ]
Subtraction of fractions: Numerator: [ ad - bc ], Denominator: [ bd ]
Multiplication of fractions: Numerator: [ ac ], Denominator: [ bd ]
Division of fractions: Numerator: [ ad ], Denominator: [ bc ]

Slope of two points (x1, y1) and (x2, y2): 
Input:  [x1 ], [ y1 ], [ x2 ], [ y2 ]
Output:  [ slope ]:  (y2 - y1)/(x2 - x1);  [ -m^-1 ]:   -(x1 - x2)/(y1 - y2)

Keyboard 9:  Linear Equations
Modifiers: [ 2nd ], [ 5th ]

Linear Form:  ax + by = c
s(x) and t(x) contains this form. 
Input:  [ ax1 ], [ by1 ], [ cx0 ]
Output: [ x-int ]: x-intercept of s(x); [ y-int ]: y-intercept of s(x);
[ s(x)= ]: solve for y given x; [ s^-1(x) ]: solve for x given y

Slope Intercept Form: mx + b
f(x) and g(x) contains this form
Input: [ mx1 ], [ bx0 ]
Output: [ f(x)= ]:  solve for y given x; [ f^-1(x) ]: solve for x given y

Keyboard 10: Quadratic Equations
Modifiers: [ 3rd ], [ 5th ]

Equation:  j(x) = a0 *x^2 + a1 * x + a2
Input:  [ a0x^2 ], [ a1x^1 ], [ a2x^0 ]

Output:
Roots:  Real: [ x21  ], [ x22 ];  Imaginary:  [ x21i ], [ x22i ]
[ D2 ]: discriminant

Keyboard 11:  Cubic Equation - Modifiers [ 2nd ], [ 3rd ], [ 5th ]

Keyboard 12:  Quartic Equation - Modifiers [ rad/deg ] set to deg, [ 5th ]

Keyboard 16:  3 x 3 Linear System - Modifiers [ 6th ]

Keyboard 20: Geometry 
Modifiers:  [ rad/deg ] set to deg, [ 6th ]

Sphere:  Input:  r.sp (radius).  Output: D.sp (diameter), V.sp (volume), S.sp (surface area)
Circle: Input: r.c (radius).  Output: D.c (diameter), A.c (area), C.c (circumference)
Trapezoid: Input: b1 (base 1), b2 (base 2), h/t (height).  Output: A/t (area)
Rectangle:  Input: l.r (length), w.r (width).  Output: A.r (area), P.r (perimeter)
Triangle: Input: a.t (side a), b.t (side b), c.t (side c). Output:  A.t (area), P.t (perimeter)
Box:  Input: l.b (length), w.b (width), h.b (height).  Output: V.b (volume), S.b (surface area)

Verdict

I'm really happy with this updated version of SciPro Math, the online prompts make a huge difference, and the how-to videos are top notch.  Also, the operation of the calculator is simple and is good for quick calculations. 

This app is worth looking into and now I see the justification of spending the $9.99 on this app. 

Eddie

All original content copyright, © 2011-2019.  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.

TI-84 Plus CE: Logistic Map

TI-84 Plus CE: Logistic Map It feels like forever since I with the TI-84 Plus CE. Introduction The program LOGISTIC plots ...