On Jan 1, 2008 10:19 AM, Mansur Marvanov <nanorobocop at gmail.com> wrote:
> I have 2 matrix 11x1:
> (%i1) x:matrix([-3.6],[-3.08],[-2.56],[-2.04],[-1.52],[-1],[-0.48],[0.04
> ],[0.56],[1.08],[1.6])$
> (%i2) y:matrix([-2.397],[-0.401],[-0.577],[-1.268],[-0.933],[-0.359],[
> 1.107],[1.300],[1.703],[-0.299],[-1.417])$
> What's the easy way to plot this 11 points? My problem is to transform
> this 2 matrices to this style:
>
> (%i12) xx:[10, 20, 30, 40, 50]$
> (%i13) yy:[.6, .9, 1.1, 1.3, 1.4]$
> (%i14) xy:[[10,.6], [20,.9], [30,1.1], [40,1.3], [50,1.4]]$
>
I'll answer about the structural transformations -- not things specific to
plotting.
In Maxima, a matrix is represented as the operator "matrix" applied to a
list of rows, each of which is a list of columns. So to convert
m: matrix([1],[2],[3])
to the list
[1,2,3]
you have quite a few options:
1) The most direct, general, generalizable, and straightforward:
makelist( m[i,1], i, 1, length(m) )
2) Taking advantage of the matrix representation:
maplist(first,m)
or equivalently
maplist(lambda([r],r[1]), m)
3) Taking advantage of the matrix representation a different way:
transpose(m)[1]
or
first(transpose(m))
4) Getting trickier:
apply(append,args(m))
or
xreduce(append,args(m))
I would recommend approach (1) because it relies the least on the
peculiarities of Maxima's representation, acts consistently with other
representations (hasharrays) and other dimensions of matrix, and generalizes
naturally to a plethora of cases, e.g. extract the diagonal elements
makelist(m[i,i],i,1,length(m)))
or extract pairs from two matrices
makelist( [m[i,1], n[i,1]], i, 1, length(m) )
The other ones are cute shortcuts -- and some are more efficient (but who
cares) -- but are brittle and don't teach you techniques you can use in
other cases.
-s