TI-89 Row Reduction Program Troubleshooting

Click For Summary

Discussion Overview

This discussion revolves around troubleshooting a matrix row reduction program written for the TI-89 calculator. Participants explore issues related to the program's performance, particularly its failure to fully reduce matrices in certain cases. The conversation includes technical explanations, debugging strategies, and alternative approaches to matrix reduction.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes a function for matrix row reduction that works inconsistently, sometimes failing to fully reduce matrices.
  • Another suggests debugging by printing the matrix at various steps to observe the process and identify errors.
  • A participant raises a concern about potential round-off errors when checking for zero, proposing that a threshold check (x < some small number) might be more effective.
  • Another participant mentions a built-in function on the TI-89 for matrix reduction, suggesting that the issue may be related to rounding errors.
  • A later reply identifies a specific bug in the code related to the row swapping function, noting that it should assign the result back to the matrix.

Areas of Agreement / Disagreement

Participants express differing views on the cause of the issue, with some attributing it to rounding errors and others identifying a specific bug in the code. The discussion remains unresolved regarding the broader implications of these issues on the program's reliability.

Contextual Notes

Participants mention potential limitations related to numerical precision and the handling of zero in the context of matrix operations, but these aspects are not fully resolved.

0rthodontist
Science Advisor
Messages
1,229
Reaction score
0
I wrote this in September so that I could do matrix row reduction on my TI-89. It works, usually, but sometimes it doesn't row reduce all the way. Any ideas what I've done wrong? Or is it just some strange quirk of the calculator?

If you don't know TI-89 code, it is self explanatory except for a few built in matrix functions which I explained with C++ style comments.

Code:
solvemat(x)   	// the name of the function.  x is the matrix
Func           	//stating that it is a function and not a program
Local j, L, i, k, o  // These are integers.  Note:  
		//Sorry about the non-
		//descriptive names, I had to type on an 
		//alphabetic non-qwerty 
             	//keyboard so I didn't want them to be long
// j and L will be dealt with shortly
// i is the loop variable for columns
// k is the loop variable for rows
// o keeps track of the last row that properly starts with a 1

colDim(x) - 1 -> j  //colDim(x) = number of columns in x.  -> j 
                   // means "assign to j"
rowDim(x) -> L 	  //rowDim(x) = number of rows in x
0->o             //o is initialized to 0
For i, 1, j, 1  // for(i = 1; i <= j; i++)
	o+1 -> k
	While x[k, i] = 0
		k + 1 -> k
		If k > L
			Goto down //I know it's lame but there
	EndWhile		//is no "continue" in TI-89 basic

	mRow(1/(x[k, i]), x, k) -> x

		/* this built-in matrix solving function means 
		   "multiply row k of matrix x
		   by 1/(x[k, i]) and put the result back into
		   matrix x." What I am doing here is putting
		   a 1 at the beginning of the row */

	rowSwap(x, k, o+1) // swaps row k and row o+1

	o+1 -> o	//I could have done this a line earlier
			// and had neater code, but I didn't
 
/* Now I have a row that is in the proper location, and it has
 a 1 at the beginning of it.  Now I will use that row to
 eliminate all the nonzero elements of the matrix above and below the 1. */

	For k, 1, L, 1 // for(k = 1; k <= L; k++) also L = 
			// rowDim(x) from earlier

		If k = o // that's an 'o'
			Goto d2

		If x[k, i] != 0
			mRowAdd(-x[k, i], x, o, k) -> x

	/* This built-in matrix solving function means
	"multiply row o of matrix x by -x[k, i] and add the
	result to row k, and the resulting matrix goes back
	into matrix x */

		Lbl d2
	EndFor
	Lbl down
EndFor

Return x

EndFunc

The matrix I am trying to do is
1 -1 0 5
-1 1 5 2
0 1 1 0

The solution of this matrix is
1 0 0 18/5
0 1 0 -7/5
0 0 1 7/5

But my function, solvemat(x), spits this out instead
1 1/4 0 13/4
0 5/4 0 -7/4
0 -1/4 1 7/4

If I do solvemat(solvemat(x)) it finishes the row reduction and returns the correct result. And the strangest thing is that if I alter the "1" in position (2, 2) of the original matrix x, the program runs correctly even if I only altered the 1 to, say, 1.000001.
 
Physics news on Phys.org
Probably the easiest way to debug it is to have it frequently print out the matrix, so you can watch what steps its performing, and in what order. That way, you can see when it's doing something wrong.
 
I notice that you have a conditional checking when x=0, what happens if due to round off errors x is very close to (as close as the calulator can get) but not equal to zero. If you were to check for x< (some very small number) You might resolve your problem.
 
The TI-89 has this function built-in using the simultanious equation solver flash-app that comes installed by default. After you enter your matrix (leave it in homogenious form - the solution side of the augmented matrix doesn't really make a difference) press solve, and after that, I forget the exact function key you have to press, but its labled something along the lines of "view". It will switch between different views, including one that you are looking for. I believe there's also a way to export the solution as a matrix.

As far as your program, it must be rounding error somewhere as others have already stated. I'll give the debugging a go once I get home (don't have my 89 with me).
 
Ah, no, it's not roundoff, I found the bug and forgot to post it. The bug is:
rowSwap(x, k, o+1)
It should be
rowSwap(x, k, o+1) -> x

Thanks evgeny, I didn't know that.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
Replies
14
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K