matrix element operation
#1

Hi, is it possible to do matrix element operation on the hp48 or hp50g?

In exemple, in matlab, if A = [1 2 3] and B = [2 3 4]

A.*B gives [1*2 2*3 3*4] -> [2 6 12]

Or A./B gives [1/2 2/2 3/4] -> [.5 1 .75]

Or A.^B gives [1^1 2^3 3^4] -> [1 8 81]

Thank you :)

#2

In HP50g at least it exists the function HADAMARD, that multiplies 2 matrices term by term. Very useful for business purposes, but not for physics or mathematics.

I don't know how to divide, because 1/[matrix] is a defined operation - and different.

#3

You could use lists instead of vectors:

1st example: A * B

4: {1 2 3}
3: {2 3 4}
2: 2
1: \<< * \>>
DOLIST

(PRG -> LIST -> PROC -> DOLIS)

Cheers

Thomas

PS: I guess the next question will be, how to turn a vector into a list:

\<<
OBJ\->
OBJ\->
DROP
\->LIST
\>>
#4

Enter the values as lists using { } or 1 2 3 3 ->LIST and you get the results you desire.

#5

Hi,

On the 50G you can use the HADAMARD command for this type of matrices multiplication :

[1 2 3] [2 3 4] HADAMARD

-> [2 6 12 ]

To transform LIST <-> MATRICE, uses AXL

[ 1 2 3 ] AXL -> { 1 2 3 }

{ 1 2 3 } AXL -> [ 1 2 3 ]

[1 2 3] 'a' STO [2 3 4] 'b' STO

« a b HADAMARD

a AXL b AXL / AXL

a AXL b AXL ^ AXL

»

You can create news commands

« AXL SWAP AXL SWAP / AXL » 'MDiv' STO

« AXL SWAP AXL SWAP ^ AXL » 'MPuis' STO

There is no need of DOLIST in this case. If you use lists instead of matrices * / and ^ does the job

{ 1 2 3 } { 2 3 4 } * -> { 2 6 12 }

{ 1 2 3 } { 2 3 4 } / -> { 1/2 2/3 3/4 }

{ 1 2 3 } { 2 3 4 } ^ -> { 1 8 81 }

Symbolic are allowed

{ 1 2 3 } { 'A' 'B' 'C' } ^ -> { 1^A 2^B 3^C }

Edited: 21 May 2011, 5:59 p.m.

#6

Quote:
There is no need of DOLIST in this case.

Thanks for the hint. This works also with the 48G.

Quote:
Symbolic are allowed

{ 1 2 3 } { 'A' 'B' 'C' } ^ -> { 1^A 2^B 3^C }


I get the following with the 48G:

{ 1 2 3 } { 'A' 'B' 'C' } ^ -> { 1 '2^B' '3^C' }

Cheers

Thomas

#7

>I get the following with the 48G:

>{ 1 2 3 } { 'A' 'B' 'C' } ^ -> { 1 '2^B' '3^C' }

>Cheers
>Thomas

Seems different on the 50


1 'A' ^ -> 1^A

EVAL -> 1

(I suppose that 'A' don't exists)

#8

Not regarding the devices you ask, but probably still helpful:

On ND1, an iOS app with a feature set that closely resembles a 50g without CAS but with other additions (incl. programmability in RPL+ and JavaScript), "lists" and "vectors" are unified, and [1 2 3] [2 3 4] * will return [2 6 12].

"+", "-", "1/x" and all single-valued operators and functions (such as "sin", "!", "loggamma", ...(a list of >100)) work on both real and symbolic vectors.

This also works with large vectors (of, say, 10^5 elements).

The DOLIST and DOSUBS techniques mentioned also work, and, as on the 48 and 50g, can be used on more than two vectors at once.

48, 50g, ND1 have other vector-processing type functionality, btw, sometimes hiding under unusual names. The common "fold" operation is known as STREAM, for example.

#9

Hi,

I also use MatLab, but I own only an HP-28S. That why to get .* .+ ./ or any vectorialized operation on matrix or line/column vector on my HP28, I have to use a dedicated program:

Considering two matrix/vectors A and B of the same shape :

A B « * » EXE2 returns matrix/vector ‘A.*B’
A B « / » EXE2 returns matrix/vector ‘A./B’
A B « ^ » EXE2 returns matrix/vector ‘A.^B’
etc

where EXE2 is :
« -> B prg
«
1 @@ initialize i at first position
DO
DUP2 GET @@ A i GET
OVER B SWAP GET @@ B i GET
prg EVAL @@ execute 'prg' for each i-element
PUTI @@ store result
UNTIL DUP 1 == END @@ loop for each i-element
DROP
»
»
'EXE2' STO

This way also si possible on HP48/49/50 and you don’t have to worry about objet type list or array !
The only restriction is that the function « … » pick exactly two arguments in the stack and returns only one (exactly as * / ^ + - etc. ) and a lot of dyadic functions or programs.

[ 1 2 3 ]   [ 10 20 30 ] « * »  EXE2 is  [10 40 90]

[ 1 2 3 ] { 10 20 30 } « * » EXE2 is [10 40 90]

{ 1 2 3 } { 10 20 30 } « * » EXE2 is {10 40 90}

[[ 1 2 3 ]] { 10 20 30 } « * » EXE2 is [[10 40 90]]

[[ 1 ] [[ 10 ]
[ 2 ] [ 40 ]
[ 3 ]] [ 10 20 30 ] « * » EXE2 is [ 90 ]]


[ 1 2 3 ] [[ 10 ]
[ 20 ]
[ 30 ]] « * » EXE2 is [10 40 90]

'A' { 10 20 30 } « * » EXE2 is 'A' but comptutation have change contents of register 'A'

Edited: 22 May 2011, 4:48 p.m.



Possibly Related Threads…
Thread Author Replies Views Last Post
  AFTER HP-Prime update, Shift+Matrix CRASHES Joseph Ec 3 2,002 12-06-2013, 11:06 AM
Last Post: Joseph Ec
  HP Prime Matrix TERRIBLE bug and question uklo 19 4,961 11-25-2013, 12:10 PM
Last Post: Mic
  HP Prime: editing a matrix Alberto Candel 6 2,299 11-20-2013, 06:26 PM
Last Post: Helge Gabert
  Absolute Value and Matrix BruceTTT 5 2,055 11-11-2013, 11:52 PM
Last Post: Walter B
  WP-34S Matrix operations with routine-local registers? Tom Grydeland 1 1,157 09-04-2013, 10:46 AM
Last Post: Marcus von Cube, Germany
  Matrix Characteristic Polynomial - Reloaded. Ángel Martin 12 3,322 08-22-2013, 05:33 PM
Last Post: Thomas Klemm
  [HP-Prime CAS] list[x,y,z], vector[x, y, z ] ... data type operation? CompSystems 1 1,174 08-22-2013, 03:30 PM
Last Post: Joe Horn
  Matrix Richard Berler 3 1,390 08-18-2013, 06:24 PM
Last Post: Paul Dale
  Advantage/CCD Matrix Challenge Ángel Martin 1 1,141 08-09-2013, 06:22 PM
Last Post: Thomas Klemm
  [HP -Prime CAS] List, Matrix, Vector as one Array? CompSystems 0 972 07-26-2013, 05:22 PM
Last Post: CompSystems

Forum Jump: