matrix diagonal
From: Tommy (warf_at_inwind.it)
Date: 07/22/04
- Next message: Cesar Rabak: "Re: [newbie] siblings and surnames"
- Previous message: Fabio: "Re: [newbie] siblings and surnames"
- Next in thread: Pento: "Re: matrix diagonal"
- Reply: Pento: "Re: matrix diagonal"
- Reply: student: "Re: matrix diagonal"
- Reply: Tommy: "Re: matrix diagonal"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 22 Jul 2004 03:51:41 -0700
I've express the matrix like a list of lists, I'd like to extract
diagonal element, so I write this code, but it doesn't work as i
expected:
Could you help me, pleaseeeee?
matrix([[1,0],[0,1]]).
find_n(0,[E|_],E).
find_n(N,[_|C],E) :- N > 0, N1 is N - 1, find_n(N1,C,E).
unisci2(A,L,[A|L]):- atomic(A),!.
diag(M,N,L1):-diag(M,N,L1,[],0).
diag(M,N,L1,L,N):-write(L1).
diag(M,N,L,L,Ind):-find_n(Ind,M,E1),find_n(Ind,E1,E2),merge2(E2,L,L1),Ind2
is Ind+1,diag(M,N,L1,L1,Ind2).
The Prolog answer is:
matrix(M),tlength(M,R),diag(M,R,L1).
[1, 1]
M = [[1, 0], [0, 1]]
R = 2
L1 = []
I'd like to have L1=[1,1]...
Thanks in advance
Tommy
- Next message: Cesar Rabak: "Re: [newbie] siblings and surnames"
- Previous message: Fabio: "Re: [newbie] siblings and surnames"
- Next in thread: Pento: "Re: matrix diagonal"
- Reply: Pento: "Re: matrix diagonal"
- Reply: student: "Re: matrix diagonal"
- Reply: Tommy: "Re: matrix diagonal"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|