HP Forums
Create a matrix - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Create a matrix (/thread-12268.html)

Create a matrix - DrD - 01-26-2019 11:19 AM

Specifically, I would like to create a matrix, using a 3 element specified pattern, (tridiagonal), with a specified number of rows and columns. The center value of the pattern should be on the main diagonal of the matrix:

Some kind of variation on this (non-working) theme:
makemat([-1,2,-1], 5,5); // Uses the pattern -1,2,-1 in a 5x5 matrix, with 2 on the main diagonal:


I (think) this can be done using the matlab eye() command, for example. Any ideas how to create a custom matrix in similar fashion, on the prime?


RE: Create a matrix - JMB - 01-26-2019 12:00 PM

MAKEMAT(IFTE(I=J,2,IFTE(J=I-1 OR J=I+1,-1,0)),5,5)

RE: Create a matrix - DrD - 01-26-2019 03:18 PM

Thank you for your suggestions!

Something interesting happens when I copy from your post, into the [CAS] (emulator):
MAKEMAT(IFTE(I=J,2,IFTE(J=I-1 OR J=I+1,-1,0)),5,5) :

CAS changed changed all of the IFTE()'s to when()'s:
MAKEMAT(when(I=J,2,when(J=I-1 OR J=I+1,-1,0)),5,5)

Then I recalled that result to the command line, it changed all of the when()'s to:
MAKEMAT(((I = J)? 2 : (((J = (I-1)) OR (J = (I+1)))? -1 : 0)),5,5)

I've never seen that last format before, on the prime. Maybe an XCAS shorthand?

RE: Create a matrix - JMB - 01-26-2019 05:49 PM

The programming language C has this same ternary operator

Cond ? a : b

If Cond is true returns a, otherwise returns b.