Create a matrix
|
01-26-2019, 11:19 AM
Post: #1
|
|||
|
|||
Create a matrix
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: [[2,-1,0,0,0], [-1,2,-1,0,0], [0,-1,2,-1,0], [0,0,-1,2,-1], [0,0,0,-1,2]] 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? -Dale- |
|||
01-26-2019, 12:00 PM
(This post was last modified: 01-26-2019 12:37 PM by JMB.)
Post: #2
|
|||
|
|||
RE: Create a matrix
Try:
MAKEMAT(IFTE(I=J,2,IFTE(J=I-1 OR J=I+1,-1,0)),5,5) Or: MAKEMAT(IFTE(I=J,2,IFTE(ABS(I-J)=1,-1,0)),5,5) Josep Mollera. HP PRIME, HW: C, SW: 2.2.15157 (2024-09-01). |
|||
01-26-2019, 03:18 PM
Post: #3
|
|||
|
|||
RE: Create a matrix
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? |
|||
01-26-2019, 05:49 PM
(This post was last modified: 01-26-2019 05:50 PM by JMB.)
Post: #4
|
|||
|
|||
RE: Create a matrix
The programming language C has this same ternary operator
Cond ? a : b If Cond is true returns a, otherwise returns b. https://en.wikipedia.org/wiki/%3F: Josep Mollera. HP PRIME, HW: C, SW: 2.2.15157 (2024-09-01). |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)