▼
Posts: 217
Threads: 21
Joined: Aug 2007
I've just posted an article to my web site, A Matrix MultiTool for the HP 35s Programmable Calculator.
This is my second attempt at a large program for the HP 35s. My previous program (Curve Fitting for the HP 35s Programmable Calculator) addressed the curve fitting shortcomings of the 35s. This program is a start at doing the same for matrix functionality.
Given an N×N matrix A, and an Nelement vector b, the matrix multitool will do the following:
 Compute A^{1}.
 Compute the determinant of A.
 Solve the system of linear equations, Ax=b, giving column vector x.
 Quickly solve additional Ax=b systems for different b vectors.
The program uses Gaussian elimination with partial pivoting to compute results 1, 2, and 3 simultaneously. It uses matrixvector multiplication for operation 4.
Enjoy!
Stefan
▼
Posts: 70
Threads: 6
Joined: Oct 2007
Can you do a version of the equation solver that solves banded symmetrical equations where the only the halfbandwidth of coefficients plus the rhs vector are stored?
Just to make it difficult, can the solution progressively overwrite the original RHS vector, overwriting also the coefficient array space as working storage, and not use any additional storage?
I suggest the halfbandwidth storage be treated as if stored in a 1D array with a simple algorithm for the offset that points to nonzero (i,j) terms of the full square matrix, in the 1D compressed array.
I assume that you are fully familiar with all that I am talking about (just ask me if I am not being clear). I do not assume that you will be able to find time to do this, but if you could do so then it would be a major step towards the frame analysis program I am hoping someone will also do for HP35s engineer users!

John
▼
Posts: 217
Threads: 21
Joined: Aug 2007
I understand what you're talking about, but I can't really say I'm "fully familiar" with it. However, I think I'm done writing large programs for the 35s for now. I have too many other things on the go, but I had to get the calculator programming thing out of my system.
Stefan
▼
Posts: 70
Threads: 6
Joined: Oct 2007
Understand perfectly. Thanks for posting this one.
I'll save a copy. Very useful.

John
Posts: 151
Threads: 18
Joined: Aug 2007
Good work! I may have to check this out :)
Posts: 305
Threads: 17
Joined: Jun 2007
Stefan, you say on the website that it takes a long time for a loarge system. Would you tell how long it takes to invert an 18x18 matrix full of random numbers?
▼
Posts: 217
Threads: 21
Joined: Aug 2007
I haven't tried such a large example yet, but I'd suspect somewhere between one and two hours.
Stefan
▼
Posts: 305
Threads: 17
Joined: Jun 2007
Wow! That's longer than I would have expected. For comparison, the HP48G takes 23 seconds, and the HP50 takes 12 seconds.
Have you tried calculating the determinant of Hilbert matrices of order 5, 6 or 7 and comparing to the exact results? I wonder how the 35s does for accuracy on long calculations such as these.
I think you can find these tests done by Palmer on this forum.
▼
Posts: 217
Threads: 21
Joined: Aug 2007
Don't forget that these are builtin operations on the 48/49/50 series, so they're likely coded in assembly language or compiled C code. I'm sure if you implemented them in RPL, they'd be quite a bit slower.
Anyway, I did some timing up to 7x7 just now, and based on those, and the fact that Gaussian elimination is O(N^3), it's faster than I expected. 18x18 should take about 18 to 20 minutes.
Stefan
▼
Posts: 305
Threads: 17
Joined: Jun 2007
I haven't forgotten, and they are indeed coded in assembly. Paul McClellan recoded all the matrix operations in assembly using internal 15 form numbers.
The better estimate of timing is more like what I would have expected.
Have you tried the Hilbert matrices? If so, what kind of results did you get?
▼
Posts: 217
Threads: 21
Joined: Aug 2007
Just tried a 6x6 Hilbert matrix. The program comes up with a determinant of 5.3672816017e18
Calculating the same determinant exactly (in Maple, using rational numbers) and then evaluating the resulting fraction to the same number of digits, I get 5.3672988874e18
So the Matrix MultiTool's answer has a relative error of 3.2e6.
How does the 48 do on this?
Stefan
Edited: 4 Nov 2007, 2:59 p.m.
▼
Posts: 150
Threads: 6
Joined: Sep 2007
The 50G creates a 6x6 Hilbert matrix with its own command in a fraction of a second and yields 5.36729988736E18 or 1/186313420339200000 for the determinant in another fraction of a second.
Posts: 305
Threads: 17
Joined: Jun 2007
Quote:
Just tried a 6x6 Hilbert matrix. The program comes up with a determinant of 5.3672816017e18
Calculating the same determinant exactly (in Maple, using rational numbers) and then evaluating the resulting fraction to the same number of digits, I get 5.3672988874e18
So the Matrix MultiTool's answer has a relative error of 3.2e6.
How does the 48 do on this?
Stefan
The 48G gets 5.36728432771E18, but beware, this result should not be compared to 5.36729988736E18 because the calculator can't be expected to get that result. See my posting:
http://www.hpmuseum.org/cgisys/cgiwrap/hpmuseum/archv015.cgi?read=72273#72273
The correct value to use as the standard of comparison for a calculator that uses 12 digit numbers in its calculations is 5.36728432456E18. Using this as a standard of comparison, the HP48G got 3 more correct digits than your 35S program. This is the expected result since the 48G uses 15 digit arithmetic for the calculation, 3 more than you're using.
The LCM of the denominators in a 6x6 Hilbert matrix, if you want to use the other method I mentioned in the earlier post, is 27720. The determinant in that case should be exactly 2435091120, but the HP48G gets 2435091119.56
Posts: 901
Threads: 113
Joined: Jun 2007
Quote:
Just tried a 6x6 Hilbert matrix. The program comes up with a determinant of 5.3672816017e18
Calculating the same determinant exactly (in Maple, using rational numbers) and then evaluating the resulting fraction to the same number of digits, I get 5.3672988874e18
So the Matrix MultiTool's answer has a relative error of 3.2e6.
How does the 48 do on this?
Stefan
You might want to compare your resolts on the 35s with the resulots which are obtained with some classic machines. For the 6x6 Hilbert:
HP41 Math Pak..... 5.367369294e18
HP28S................... 5.36728676731e18
and for the modified 6x6 Hilbert (multiplied by 27720)
HP41 Math Pak..... 2435060936
HP28S................... 2435091046.63
I don't have a 35s but I understand that it offers a very large number of data registers. If that is so then I suggest that you find a way to preserve the input matrix so that it can be reviewed or modified if the user doesn't like his results and suspects that he may have made an entry error. This is particularly important when working with a machine which cannot print the input or store the input offline.
▼
Posts: 217
Threads: 21
Joined: Aug 2007
It looks like my program's results are better than the 41C Math Pac and very slightly worse than the 28S.
Quote:
I don't have a 35s but I understand that it offers a very large number of data registers. If that is so then I suggest that you find a way to preserve the input matrix so that it can be reviewed or modified if the user doesn't like his results and suspects that he may have made an entry error. This is particularly important when working with a machine which cannot print the input or store the input offline.
Agreed, but I wanted to keep the program as simple as possible. At the moment, there is at least the UnSolve feature, so you can get the original matrix (or a close facsimile thereof) back. Of course this doesn't work if your data entry error made the system singular, since the matrix is then left in a partially inverted state.
Stefan
▼
Posts: 901
Threads: 113
Joined: Jun 2007
Quote:
It looks like my program's results are better than the 41C Math Pac and very slightly worse than the 28S.
If you go to the "Even More Results with Matrices" mentioned in my 4 November posting you will see that the matrix routines in the 41C Advantage module yield results for 7x7, 8x8 and 9x9 that are significantly better than those from the 41C MathPac. Some limited testing by myself and others indicates that the results from the Advantage module are very similar to those from the HP15C. I don't have either th Advantage module or an HP15C so I can't provide the 6x6 results.
Quote:
... At the moment, there is at least the UnSolve feature, so you can get the original matrix (or a close facsimile thereof)...
I still don't have a 35s. I do have a 28s which has an UNDO function. If one enters a matrix into the stack, inverts it and then uses the UNDO function one will get back the exact original matrix. If instead one does a second inversion one gets back a matrix that is close to the original matrix. The LAST function on the 28s will also bring back the original matrix. But if one has done some other work after the original inversion the original matrix is lost unless it has been stored. To me the ability to store the original matrix is one of the glorious features of all the graphic calculators whether made by HP or by TI.
The manual for either the HP41C MathPac or Advantage Pac (I can't remember which one and I have neither available at this time) suggests that the user can get back his original matrix by doing a second invert and even offers an example to demonstrate that. Unfortunately the example is done in Fix 2 (or maybe it was Fix 4) and while the displayed result suggests an exact recovery switching to Fix 9 willl show that only an approximate recovery was achieved.
Posts: 901
Threads: 113
Joined: Jun 2007
Quote:
Wow! That's longer than I would have expected. For comparison, the HP48G takes 23 seconds, and the HP50 takes 12 seconds.
Have you tried calculating the determinant of Hilbert matrices of order 5, 6 or 7 and comparing to the exact results? I wonder how the 35s does for accuracy on long calculations such as these.
I think you can find these tests done by Palmer on this forum.
The test results Rodger mentioned can be found in Message No. 2 posted on 30 May 2005 in the thread "Even More Results with Matrices". It is toward the bottom of Archive 15 or can be found directly by going to http://www.hpmuseum.org/cgisys/cgiwrap/hpmuseum/archv015.cgi?read=74206 .
