Post Reply 
Colinear Points
12-25-2013, 04:48 PM
Post: #1
Colinear Points
Following up on a HP28s example made by Damien in another sub-forum, I thought to try to do the same on the Prime.

Damien's examples and explanation:

A(a, a'), B(b, b'), C(c, c') are lined up if the determinant = 0
|a a' 1|
|b b' 1| = 0
|c c' 1|

Examples:

(2,2)
(4,1)
(5,3) -> The points are not colinear

(2,-3)
(4,1)
(5,3) -> The points are colinear

Code:

EXPORT COLINEAR()

BEGIN

// Declare local variable to hold matrix and state
LOCAL Points,s;

// Preserve entry mode and set to textbook
s:=Entry;
Entry:=0;

// Create input matrix 3 rows by 2 cols
Points:=[[0,0],[0,0],[0,0]];

// Allow input of points and add column of one's to make square
EDITMAT(Points);
ADDCOL(Points,[1,1,1],3);

// Check if determinant is equal to 0 and display result in MSGBOX
IFERR 1/det(Points) 
THEN MSGBOX("The points are colinear") 
ELSE MSGBOX("The points are not colinear") 
END;

// Reinstate entry mode
Entry:=s;
END;

The program must be run in Textbook or Algebraic as if not the calculator will crash, so to avoid that I preserve the Entry mode in a local variable and reinstate it at the end. It is also only relevant to 3 points and does not check if more points have been entered in the matrix editor.

However, when running the program off the stack whilst in RPN mode it always return a 2 (which is the Entry state) to the stack. I have looked but cannot find a way to avoid this undesired result in the program. Does anybody have a suggestion for how this could be achieved?

Cheers, Terje
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Colinear Points - Terje Vallestad - 12-25-2013 04:48 PM
RE: Colinear Points - Han - 12-25-2013, 05:33 PM
RE: Colinear Points - Terje Vallestad - 12-25-2013, 06:56 PM
RE: Colinear Points - Han - 12-26-2013, 01:59 AM
RE: Colinear Points - debrouxl - 12-25-2013, 06:13 PM
RE: Colinear Points - Terje Vallestad - 12-25-2013, 07:05 PM
RE: Colinear Points - patrice - 12-25-2013, 07:47 PM
RE: Colinear Points - Terje Vallestad - 12-25-2013, 09:35 PM



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