
Discussion BoardsOpen MenuDiscussion Boards Open Menu
 Welcome to the Community
 1 categories, 7 boards
 Live with HP Experts
 1 boards
 Converged Systems
 1 categories, 1 boards
 Networking
 6 categories, 22 boards
 Operating Systems
 7 categories, 77 boards

BlogsOpen MenuBlogs Open Menu

Community Knowledge BaseOpen MenuCommunity Knowledge Base Open Menu

Printing, Personal Computing and Mobile BoardsOpen Menu
Migrating to HP Support ForumsPrinting, Personal Computing and Mobile Boards
Migrating to HP Support Forums Open MenuToday we’ll be migrating all boards within the Printing and Digital Imaging, Desktops and Workstations, and Mobile categories to the HP Support Forums. Please see this post for full details on the migration, and how to get to your content. 
EnglishOpen Menu
 Community Home
 >
 Mobile
 >
 Calculators
 >
 Re: HP50g  subset of a matrix  how to
 Subscribe
 Mark Topic as New
 Mark Topic as Read
 Float this Topic to the Top
 Bookmark
 Subscribe
 Printer Friendly Page
HP50g  subset of a matrix  how to
 Mark as New
 Bookmark
 Subscribe
 Subscribe to RSS Feed
 Highlight
 Email to a Friend
 Report Inappropriate Content
07082014 02:30 AM
Could somebody give an example how to extract a subset of a matrix, say extract a double column matrix from NxM matrix?
I have data in NxM matrix and want to perform approximation with LAGRANGE command, which needs a 2 column input data. For example from 3x4 matrix
1 1 1 2
2 4 8 4
3 9 27 6
extract columns 1 & 3, ie. get 3x2 matrix
1 1
2 8
3 27
Thanks
Re: HP50g  subset of a matrix  how to
[ Edited ] Mark as New
 Bookmark
 Subscribe
 Subscribe to RSS Feed
 Highlight
 Email to a Friend
 Report Inappropriate Content
07082014 05:23 AM  edited 07082014 05:25 AM
I doubt this is the simplest way, but at least it works. Just put your matrix on the stack then do this:
DUP
{1 3} {3 3} SUB
{1 2} SWAP REPL
{1 1} {3 2} SUB
> [[1 1] [2 8] [3 27]] as requested.
For more information about the SUB and REPL commands, see the Advanced Users Reference Manual, pages 3242 and 3199, respecively. Other useful commands for column work are >COL, COL>, COL, and COL+ (pages 339 and 340).
Re: HP50g  subset of a matrix  how to
 Mark as New
 Bookmark
 Subscribe
 Subscribe to RSS Feed
 Highlight
 Email to a Friend
 Report Inappropriate Content
07082014 02:52 PM
Thank you Joe. Your solution works. After a few tests I picked another way with CSWP command. For the special case above it would be something like
<< 2 3 CSWP {1 1} {3 2} SUB >>
In general it could be something like
<< > T I
<< T 2 I CSWP DUP
SIZE 1GET 2 2 >LIST
{1 1} SUB
>>
>>
Program takes 2 parameters: matrix T and column number I, then extracts two columns (1 and I) from T matrix. In column 1 are x'es, in other columns are values for approximation. The line with SIZE, GET and >LIST is to detetrmine number of rows of the matrix (I don't know simpler way :)
BTW, SCATRPLOT takes 2 columns from NxM matrix
Thank you for the hint.
Re: HP50g  subset of a matrix  how to
[ Edited ] Mark as New
 Bookmark
 Subscribe
 Subscribe to RSS Feed
 Highlight
 Email to a Friend
 Report Inappropriate Content
07092014 07:44 AM  edited 07092014 07:51 AM
You can also use the COL command ( MTH MATRIX COL COL ).
Removes the desired column number from the matrix, returning new matrix and deleted column as a vector.
Here's a simple program.
Matrix is on Level 2 and a list of columns to delete is on level 1:
<<
SORT LIST> > n
<< n 1 + PICK
1 n FOR j
SWAP COL DROP
NEXT
>>
>>
So this:
returns this:
Re: HP50g  subset of a matrix  how to
 Mark as New
 Bookmark
 Subscribe
 Subscribe to RSS Feed
 Highlight
 Email to a Friend
 Report Inappropriate Content
07092014 10:10 PM
Here's another approach to Bart's program. Same inputs.
<< SORT REVLIST 1 << COL DROP >> DOLIST >>
Unlike Bart's program, however, this only returns the new (smaller) matrix; the original is lost.
Re: HP50g  subset of a matrix  how to
[ Edited ] Mark as New
 Bookmark
 Subscribe
 Subscribe to RSS Feed
 Highlight
 Email to a Friend
 Report Inappropriate Content
07102014 03:15 AM  edited 07102014 03:21 AM
Joseph Horn wrote:<< SORT REVLIST 1 << COL DROP >> DOLIST >>
Brilliant solution Joe. I sometimes forget the 50g has recursive commands like DOLIST.
Joseph Horn wrote:Unlike Bart's program, however, this only returns the new (smaller) matrix; the original is lost.
That's because I used PICK instead of ROLL, but usually only the answer is required anyway  so your solution is "cleaner" :).