Colinear Points

12252013, 04:48 PM
Post: #1




Colinear Points
Following up on a HP28s example made by Damien in another subforum, 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:
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 

12252013, 05:33 PM
Post: #2




RE: Colinear Points
Thanks for sharing! Quick question, though: Why check if 1/det(...) produces an error, as opposed to simply checking if det(...) is nonzero?
Code:
Graph 3D  QPI  SolveSys 

12252013, 06:13 PM
Post: #3




RE: Colinear Points
You can also use the (x3  x1) * (y2  y1) + (y3  y1) * (x1  x2) formula for computing collinearity without det() or even a matrix. 4 subtractions, 2 multiplications and 1 addition make this formula highly suitable to implementation on embedded platforms.
(just looked up the definition again on the Internet, I seldom use it and never remember it ) 

12252013, 06:56 PM
Post: #4




RE: Colinear Points
(12252013 05:33 PM)Han Wrote: Thanks for sharing! Quick question, though: Why check if 1/det(...) produces an error, as opposed to simply checking if det(...) is nonzero? I'm probably a glass half empty man rather than half full...... :) However, I needed a trigger/trap and ISERR was the first one I found in the manual. Being new to programming PPL I did not look further. Would it in your opinion be a benefit to look for a positive rather than a negative in this instance? Thanks, Terje 

12252013, 07:05 PM
Post: #5




RE: Colinear Points
(12252013 06:13 PM)debrouxl Wrote: You can also use the (x3  x1) * (y2  y1) + (y3  y1) * (x1  x2) formula for computing collinearity without det() or even a matrix. 4 subtractions, 2 multiplications and 1 addition make this formula highly suitable to implementation on embedded platforms. Thanks Debroux, To me this was more about writing my first PPL programme rather than the maths. Given the speed of the Prime and the relative ease of entering a matrix I thought using a matrix was quite a quick way of entering the required input? That said, how would you go about the programme using the formula? Using INPUT? I'm certainly here to learn. Cheers, Terje 

12252013, 07:47 PM
Post: #6




RE: Colinear Points
Your program can be made a function.
Code: EXPORT COLINEAR(Mt) Patrice “Everything should be made as simple as possible, but no simpler.” Albert Einstein 

12252013, 09:35 PM
Post: #7




RE: Colinear Points
(12252013 07:47 PM)patrice Wrote: Your program can be made a function. Thanks Patrice, No bells and whistles, but very neat. Also gets rid of my problem with a return value I didn't need. Cheers, Terje 

12262013, 01:59 AM
Post: #8




RE: Colinear Points
(12252013 06:56 PM)Terje Vallestad Wrote:(12252013 05:33 PM)Han Wrote: Thanks for sharing! Quick question, though: Why check if 1/det(...) produces an error, as opposed to simply checking if det(...) is nonzero? IFERR would be a perfectly fine solution if the only error produced from 1/det(...) is a division by zero error. However, there are other ways det(...) could produce an error (nonsquare matrix when the user accidentally creates more entries than necessary). So an error having nothing to do with colinearity would incorrectly result in the wrong conclusion of "colinear." To make the program exit gracefully when an error occurs, you may want to test the dimensions of the matrix prior to executing det(...). Graph 3D  QPI  SolveSys 

« Next Oldest  Next Newest »

User(s) browsing this thread: