cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New member
1 0 0 0
Message 1 of 4
1,061
Flag Post
HP Recommended

Solved!

How to apply a function to each element of a matrix?

HP 50g

How to apply a built-in function, such as [COLLECT()] to all elements of a list, vector or matrix?

Tags (1)
3 REPLIES 3
Highlighted
Level 6
127 126 23 48
Message 2 of 4
1,037
Flag Post
HP Recommended

Solved!

How to apply a function to each element of a matrix?

Here's one way:

 

(assumption: RPN mode)

 

1) If your target object is a vector or matrix, issue the AXL command to convert it to a list.

2) Create a small program object containing the function you want to apply.  For example, if you wanted to apply the SIN function to all elements, create a program that looks like this:

« SIN »

3) Execute the MAP command.

4) The result is a list with the function applied to each element.  If you need to convert this back into a matrix/vector, just execute another AXL command.

 

Replace the SIN function in step 2 with whatever function(s) you wish.

 

Using your example, if I had a matrix that I wished to apply the COLLECT command to, I'd do the following:

AXL
« COLLECT »
MAP
AXL

For more information about the AXL and MAP commands, see the Advanced User's Reference which is available here.

 

Hope this helps!

 

- David

0 Kudos
Highlighted
Level 9
970 953 119 185
Message 3 of 4
1,009
Flag Post
HP Recommended

Solved!

How to apply a function to each element of a matrix?

Hi,

 

MAP can be applied directly to a matrix:

 

[[ 1   2   3 ]
 [ 4   5   6 ]
 [ 7   9   9 ]]
<< SQ >>
MAP

will give

[[ 1   4   9  ]
 [ 16  25  36 ]
 [ 49  64  81 ]]

 

See page 3-141 of the AUR ( HP-50G Advanced User's Reference )

 

-Bart
_________________________________________________________
calculator enthusiast
Tags (1)
Level 6
127 126 23 48
Message 4 of 4
1,006
Flag Post
HP Recommended

Solved!

How to apply a function to each element of a matrix?

Of course you're right, Bart.  No need for the AXL.  I've been too list-focused lately! :generic:

Be alert for scammers posting fake support phone numbers on the community. If you think you have received a fake HP Support message, please report it to us by clicking on "Flag Post".
† The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation