How to perform a vec or vech operation on a matrix.



Dear, Macrakis

On Mon, Apr 13, 2009 at 4:21 AM, Stavros Macrakis <macrakis at alum.mit.edu> wrote:
> Your code looks correct.  Perhaps Var isn't really a 6x6 matrix?
>
> Here's what I get:
>
> Var: genmatrix(lambda([i,j],i+10*j),6,6)$
> vecVar:zeromatrix(21,1)$
> (k:1, for j:1 thru 6 do (for i:j thru 6 do (vecVar[k,1]:Var[i,j],k:k+1)))$
> display2d:false$
> vecVar;
> matrix([11],[12],[13],[14],[15],[16],[22],[23],[24],[25],[26],[33],[34],[35],[36],[44],
>              [45],[46],[55],[56],[66])
>
> which looks right to me....

The following is two functions written by common lisp of maxima.
Perhaps $foo2 is a function you want.

to_lisp();

(defun $foo (mat)
  (cons '(mlist simp)
	(reduce #'(lambda(x y)(append x y))
		(mapcar #'(lambda(x) (cdr x))
			(cdr mat)))))
(defun $foo2 (mat)
	   (cons '(mlist simp)
		 (reduce #'(lambda(x y)(append x y))
			 (apply #'mapcar
				#'(lambda (&rest args)`(, at args))
				(mapcar #'(lambda(x)(cdr x))
					(cdr mat))))))
(to-maxima)
(%i57) transpose(foo2(Var));

(%o57) matrix([11],[12],[13],[14],[15],[16],[21],[22],[23],[24],[25],[26],
              [31],[32],[33],[34],[35],[36],[41],[42],[43],[44],[45],[46],
              [51],[52],[53],[54],[55],[56],[61],[62],[63],[64],[65],[66])
(%i58) transpose(foo(Var));

(%o58) matrix([11],[21],[31],[41],[51],[61],[12],[22],[32],[42],[52],[62],
              [13],[23],[33],[43],[53],[63],[14],[24],[34],[44],[54],[64],
              [15],[25],[35],[45],[55],[65],[16],[26],[36],[46],[56],[66])



-- 
Yasuto TAKENAKA
? e-mail?y.takenaka at gmail.com