matrix element operation - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: matrix element operation (/thread-184535.html) matrix element operation - Sok-khieng Chum Hun - 05-21-2011 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 :) Re: matrix element operation - Jose Gonzalez Divasson - 05-21-2011 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. Re: matrix element operation - Thomas Klemm - 05-21-2011 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 \>> ``` Re: matrix element operation - Donald Ingram - 05-21-2011 Enter the values as lists using { } or 1 2 3 3 ->LIST and you get the results you desire. Re: matrix element operation - Gilles Carpentier - 05-21-2011 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. Re: matrix element operation - Thomas Klemm - 05-21-2011 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 Re: matrix element operation - Gilles Carpentier - 05-21-2011 >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) Re: matrix element operation - Oliver Unter Ecker - 05-22-2011 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. Re: matrix element operation - C.Ret - 05-22-2011 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.