Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a matrix example as per Francis' email. #65

Open
gheber opened this issue Oct 28, 2015 · 0 comments
Open

Create a matrix example as per Francis' email. #65

gheber opened this issue Oct 28, 2015 · 0 comments
Assignees

Comments

@gheber
Copy link
Owner

gheber commented Oct 28, 2015

;; Create a random matrice 4 x 6 of "density" 0.3 with |terms| <= 10:

(setf mtrx (mat-aleat 4 6 0.3 10))

========== MATRIX 4 row(s) + 6 column(s) =====
R1=[C1=1]
R2=[C1=-3][C5=9]
R3=
R4=[C2=4][C3=3][C4=-8][C5=-7]
========== END-MATRIX

;; Only & non-null term on the row 1, namely a 1 in column 1.
;; Two non-null terms in row 2, 4 in row 4, the row 3 is null.
;; Travelling in a matrix is conveniently done by P-DISP.
;; Going to the first fake-term of LEFTCOL :

CL-USER(6): (disp-p (setf p (aref (leftcol mtrx) 1)))
((1 0 NIL) (1 1 1) (0 0 NIL))

;; means it is a term in position 1-0, it is fake (nil).
;; the "lefthand" term is in position 1-1, its value is 1:
;; the above term is in position 0-0, it is fake.

;; going to the term in position 1-1:

(disp-p (setf p (left p)))
((1 1 1) (1 0 NIL) (0 1 NIL))

;; the term is in position 1-1, its lefthand term is the
;; starting point in position 1-0, the above term is
;; in position 0-1, it is fake.

;; Running through the row 4 :

(disp-p (setf p (aref (leftcol mtrx) 4)))
((4 0 NIL) (4 5 -7) (3 0 NIL))
(disp-p (setf p (left p)))
((4 5 -7) (4 4 -8) (2 5 9))
(disp-p (setf p (left p)))
((4 4 -8) (4 3 3) (0 4 NIL))
(disp-p (setf p (left p)))
((4 3 3) (4 2 4) (0 3 NIL))
(disp-p (setf p (left p)))
((4 2 4) (4 0 NIL) (0 2 NIL))
(disp-p (setf p (left p)))
((4 0 NIL) (4 5 -7) (3 0 NIL))

;; We are back to the fake term in position 4-0

;; Running through the column 5:

(disp-p (setf p (aref (uplig mtrx) 5)))
((0 5 NIL) (0 4 NIL) (4 5 -7))
(disp-p (setf p (up p)))
((4 5 -7) (4 4 -8) (2 5 9))
(disp-p (setf p (up p)))
((2 5 9) (2 1 -3) (0 5 NIL))
(disp-p (setf p (up p)))
((0 5 NIL) (0 4 NIL) (4 5 -7))

;; "Both" terms in position 0-0 are the same and are fake.

(eq (aref (leftcol mtrx) 0) (aref (uplig mtrx) 0))
T
(disp-p (aref (leftcol mtrx) 0))
((0 0 NIL) (0 6 NIL) (4 0 NIL))

;; it's one of the standard structures to implement
;; sparse matrices.

@gheber gheber self-assigned this Oct 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant