matrix diagonal

From: Tommy (warf_at_inwind.it)
Date: 07/22/04


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



Relevant Pages

  • Re: Difference between two ranges
    ... >Another frequent tasks involving lists is to create a ... >that you want to extract items. ... >> Extracting Values Common To Two Lists ... >> the following array formula in the first cell of the ...
    (microsoft.public.excel.misc)
  • Re: Variable-sized lines of text in linked list (long)
    ... My web site server log seemed horribly cluttered and 'hits' from ... log a line at a time and made lists so I ... chronologically by requestor. ... Extract data from a log record to a log element ...
    (comp.lang.c)
  • Re: Family History Software
    ... primitive database program to list my ancestors in one view, ... Note that I didn't have to type in details of the census more than once. ... selection lists for further processing? ... In addition I want to add an extract ...
    (soc.genealogy.britain)
  • Re: PyCheck for a classes defined in python and user data in PyObject_HEAD
    ... in C I want to check if a given PyObject is a xml.dom.minidom.Node (or ... how do i extract a PyTypeObject for such a class? ... I'm in a situation when i don't really need to extend python with any ... object in a key with an obscure name while in lists this would change ...
    (comp.lang.python)
  • Re: Difference between two ranges
    ... Extracting Values Common To Two Lists ... You can easily extract values that appear in both of two ... the following array formula in the first cell of the range ... which is to contain the common entries: ...
    (microsoft.public.excel.misc)