- HP Community
- >
- Tablets
- >
- Calculators
- >
- Re: How to apply a function to each element of a matrix?

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Flag Post

Solved!

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

06-24-2018 03:01 PM

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

Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Flag Post

Solved!

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

06-24-2018 07:27 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Flag Post

Solved!

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

06-25-2018 06:00 AM

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__ )

_________________________________________________________

calculator enthusiast

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Flag Post

Solved!

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

06-25-2018 06:11 AM

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

**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".

Didn't find what you were looking for? Ask the community