The Museum of HP Calculators

HP Forum Archive 17

 HP 35s Matrix Multi-ToolMessage #1 Posted by Stefan Vorkoetter on 2 Nov 2007, 10:05 a.m. I've just posted an article to my web site, A Matrix Multi-Tool 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 N-element vector b, the matrix multi-tool 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 matrix-vector multiplication for operation 4. Enjoy! Stefan

 Re: HP 35s Matrix Multi-ToolMessage #2 Posted by John Wasilewski on 2 Nov 2007, 10:54 a.m.,in response to message #1 by Stefan Vorkoetter 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 1-D array with a simple algorithm for the offset that points to non-zero (i,j) terms of the full square matrix, in the 1-D 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

 Re: HP 35s Matrix Multi-ToolMessage #3 Posted by Stefan Vorkoetter on 2 Nov 2007, 11:26 a.m.,in response to message #2 by John Wasilewski 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

 Re: HP 35s Matrix Multi-ToolMessage #4 Posted by John Wasilewski on 2 Nov 2007, 11:32 a.m.,in response to message #3 by Stefan Vorkoetter Understand perfectly. Thanks for posting this one. I'll save a copy. Very useful. --- John

 Re: HP 35s Matrix Multi-ToolMessage #5 Posted by Arne Halvorsen (Norway) on 2 Nov 2007, 11:06 a.m.,in response to message #1 by Stefan Vorkoetter Good work! I may have to check this out :-)

 Re: HP 35s Matrix Multi-ToolMessage #6 Posted by Rodger Rosenbaum on 2 Nov 2007, 4:57 p.m.,in response to message #1 by Stefan Vorkoetter 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?

 Re: HP 35s Matrix Multi-ToolMessage #7 Posted by Stefan Vorkoetter on 3 Nov 2007, 6:43 a.m.,in response to message #6 by Rodger Rosenbaum I haven't tried such a large example yet, but I'd suspect somewhere between one and two hours. Stefan

 Re: HP 35s Matrix Multi-ToolMessage #8 Posted by Rodger Rosenbaum on 3 Nov 2007, 10:02 a.m.,in response to message #7 by Stefan Vorkoetter 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.

 Re: HP 35s Matrix Multi-ToolMessage #9 Posted by Stefan Vorkoetter on 4 Nov 2007, 7:51 a.m.,in response to message #8 by Rodger Rosenbaum Don't forget that these are built-in 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

 Re: HP 35s Matrix Multi-ToolMessage #10 Posted by Rodger Rosenbaum on 4 Nov 2007, 8:56 a.m.,in response to message #9 by Stefan Vorkoetter 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?

 Re: HP 35s Matrix Multi-ToolMessage #11 Posted by Stefan Vorkoetter on 4 Nov 2007, 2:58 p.m.,in response to message #10 by Rodger Rosenbaum Just tried a 6x6 Hilbert matrix. The program comes up with a determinant of 5.3672816017e-18 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.3672988874e-18 So the Matrix Multi-Tool's answer has a relative error of 3.2e-6. How does the 48 do on this? Stefan Edited: 4 Nov 2007, 2:59 p.m.

 Re: HP 35s Matrix Multi-ToolMessage #12 Posted by Meenzer on 4 Nov 2007, 3:58 p.m.,in response to message #11 by Stefan Vorkoetter The 50G creates a 6x6 Hilbert matrix with its own command in a fraction of a second and yields 5.36729988736E-18 or 1/186313420339200000 for the determinant in another fraction of a second.

 Re: HP 35s Matrix Multi-ToolMessage #13 Posted by Rodger Rosenbaum on 5 Nov 2007, 2:32 a.m.,in response to message #11 by Stefan Vorkoetter Quote: Just tried a 6x6 Hilbert matrix. The program comes up with a determinant of 5.3672816017e-18 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.3672988874e-18 So the Matrix Multi-Tool's answer has a relative error of 3.2e-6. How does the 48 do on this? Stefan The 48G gets 5.36728432771E-18, but beware, this result should not be compared to 5.36729988736E-18 because the calculator can't be expected to get that result. See my posting: http://www.hpmuseum.org/cgi-sys/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.36728432456E-18. 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

 Re: HP 35s Matrix Multi-ToolMessage #14 Posted by Palmer O. Hanson, Jr. on 8 Nov 2007, 9:10 p.m.,in response to message #11 by Stefan Vorkoetter Quote: Just tried a 6x6 Hilbert matrix. The program comes up with a determinant of 5.3672816017e-18 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.3672988874e-18 So the Matrix Multi-Tool's answer has a relative error of 3.2e-6. 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: HP-41 Math Pak..... 5.367369294e-18 HP-28S................... 5.36728676731e-18 and for the modified 6x6 Hilbert (multiplied by 27720) HP-41 Math Pak..... 2435060936 HP-28S................... 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.

 Re: HP 35s Matrix Multi-ToolMessage #15 Posted by Stefan Vorkoetter on 9 Nov 2007, 9:20 a.m.,in response to message #14 by Palmer O. Hanson, Jr. 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 Un-Solve 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

 Re: HP 35s Matrix Multi-ToolMessage #16 Posted by Palmer O. Hanson, Jr. on 9 Nov 2007, 10:47 p.m.,in response to message #15 by Stefan Vorkoetter 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 HP-15C. I don't have either th Advantage module or an HP-15C so I can't provide the 6x6 results. Quote: ... At the moment, there is at least the Un-Solve 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 HP-41C 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.

 Re: HP 35s Matrix Multi-ToolMessage #17 Posted by Palmer O. Hanson, Jr. on 4 Nov 2007, 9:44 p.m.,in response to message #8 by Rodger Rosenbaum 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/cgi-sys/cgiwrap/hpmuseum/archv015.cgi?read=74206 .

Go back to the main exhibit hall