cancel
Showing results for 
Search instead for 
Did you mean: 
REYNEL
Level 3
38 34 1 3
Message 1 of 6
1,102
Flag Post

Solved!

Matrix summation

HP Recommended

Hi I want to debugg the following program to solve the summation of matrix mulplied by a factor as shown in the picture

summation.PNG

I stored the matrix in the variable A, t stored with the value 25 and p stored with the value 0.19

Next I run this programs

« A SIZE 1 GET 'R' STO » and then run the prog  
« A 1 R START p t 20 - ^ * + 1 'S' STO NEXT S "S" ->TAG »

I recieved a bad argument type error after getting the partial result which is ok as shown belowsumm2.PNG

After using the following program << AXL ZLIST  ZLIST >> "Z STANDS FOR SIGMA" , I got  the final result of 0.007428297 which is also ok, but I am unable to fix the error.   Any help to debug this prog or other suggestion would be very much appreciated.

Reynel

0 Kudos
5 REPLIES 5
Joe_Horn
Level 8
624 611 118 208
Message 2 of 6
Flag Post
HP Recommended

I would suggest single-stepping your program and watching what happens on the stack.  You'll see that the first problem occurs when the multiplication (*) is executed for the first time.  You are intending to multiply only the first element by p^(t-20), but you're multiplying the entire matrix by it.  Then the addition (+) is executed with only the matrix on the stack, thus giving a "Too few arguments" error.  You say that you get a "Bad argument type" error, which either means that you started with something on the stack (what?) or your actual program is different from your posted listing.

 

There are of course many ways to "fix" your program, but IMHO the best way to get the answer you seek is to eliminate the START / NEXT loop.  Just multiply the whole matrix by the constant, then sum up the elements using either CNRM (if you know ahead of time that all the elements will be positive) or your solution of AXL SigmaLIST SigmaLIST.

 

If that doesn't answer your question, please advise.  Disclaimer: I don't work for HP; I'm just another happy HP calculator user.

-Joe-
0 Kudos
REYNEL
Author
Level 3
38 34 1 3
Message 3 of 6
Flag Post
HP Recommended

Hi John,

Nice to hear from you again. You are always there for the rescue :). My intention is to multiply each element of a constant matrix by a the factor p^(t-20) with p and t as variables. The multiplication has to cycle to every element of the matrix and finally, all the elements of the new matrix has to be summed up. I got rid off the START NEXT LOOP and went through a single step by step  operation with all the elements on the stack. Finally, I  assembled all these steps in a single program where I only had to change the value of t and p and the program worked well as intended. Thank you!

 

In one of the previous threads you wrote a litlte program to do operation with two matrices/vectors. That method did not work for the element by element addition of the 2 vectors with different dimentions for  example the addition of a 4x1 matrix  [ 1 , 3, 5  ,5 ]  with a 3x1 matrix[10,9,20].  I can do this in other CAS, but not on HP 50g. Any ideas?

Thank you again!

 

0 Kudos
REYNEL
Author
Level 3
38 34 1 3
Message 4 of 6
Flag Post
HP Recommended

I fotgot to write down my final program, which works as intended.

 

«   A p t 20  - ^ * AXL SIGMALIST …SIGMALIST »

 

A (matrix) p & t declared variables.

Thank you!

 

0 Kudos
Joe_Horn
Level 8
624 611 118 208
Message 5 of 6
Flag Post
HP Recommended

@REYNEL wrote:

 

In one of the previous threads you wrote a litlte program to do operation with two matrices/vectors. That method did not work for the element by element addition of the 2 vectors with different dimentions for  example the addition of a 4x1 matrix  [ 1 , 3, 5  ,5 ]  with a 3x1 matrix[10,9,20].  I can do this in other CAS, but not on HP 50g. Any ideas? 


[1, 3, 5, 5] + [10, 9, 20] is not defined.  The HP Prime returns an answer by assuming that the second vector is [10, 9, 20, 0].  If that is what you want the HP 50g to do, then I'd write a program that finds the dimensions of both vectors, finds the larger of the two, and resizes both to that size, then adds them.  Something like this:

 

<< DUP2 SIZE SWAP SIZE MAX ROT OVER RDM UNROT RDM + >>

 

Input: Any two vectors (not matrices). Output: Their sum, with undefined elements assumed to be zeros.  Simplifying the program, or extending it to work with matrices, is left as an exercise for the student. 😉

-Joe-
0 Kudos
REYNEL
Author
Level 3
38 34 1 3
Message 6 of 6
Flag Post
HP Recommended
Hi Joe, I think I was misunderstood or did not explain correctly what I was trying to do. What I meant by "element by element addition" of two vectors of different dimensions I neant to add each element of vector X with each element of vector Y. For example , for X = [ A B C] & Y =[ D E ], I desire a vector Z= [ A+D, A+E, B+D, B+E, C+D, C+E ]. Of the 2600 + built-in functions of the HP 50 g calc is there anyone of them that would accomplish this king of task? Reading through the help manual I have discoverd interesting things but unrelated to solve this issue. I will find some apps for the program that you just wrote. Thank you expert!
Regards, reynel.
0 Kudos
† 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