![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Sep 2005
Posts: 1
Rep Power: 0
![]() |
Bizarre TI-89 matrix algebra error (not language specific)
I am trying to write a Basic program for my TI-89 calculator to solve matrices. For some weird reason this function is not built-in to the calculator, which has stuff to do mostly everything else.
I don't think this is language-specific; I think that if you know other programming languages you may be able to help. I haven't done BASIC in five years, and this is my first go at TI-89 BASIC, and it didn't take me very long to start from scratch. If you know about matrixes and you can program then you probably can help. 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 So far you're thinking, he just made some stupid error in his code that he'll catch in a minute before I even reply. But I don't think so. Point 1: Applying the function twice, solvemat(solvemat(x)) returns the correct result Point 2: The key value, where it seems to be screwing up, is on the number at position [2,2] (indexing in BASIC starts from 1). Altering that number in any way causes the program to function perfectly correctly. If I put .5 or 2 instead of 1 in that position, or even 1.0001 or 9999/10000 instead of 1, it gives the right answer. WHAT THE HELL IS GOING ON? Here is my code, with Java-style comments (the TI-89 comment character is unprintable): 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
EndFuncPlease help! It's driving me nuts. I suppose I could just make another function solvemat2(x) that is just solvemat(solvemat(x)) but I'm doing this for fun anyway and I want to know what's happening. Maybe it's a calculator bug. Last edited by Generic; Sep 7th, 2005 at 8:17 PM. Reason: changed title |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|