Dear Robert, Leo,
Thanks a lot. Imported xml tags are caused by wxMaxima (which is most
likely a bug beacuse of its ambition to enable LaTeX copy/paste of nice
formatted outputs).
The code provided for draw2d is fine.
Best, Dan
---------- Forwarded message ----------
From: Leo Butler <l_butler at users.sourceforge.net>
Date: 2013/11/19
Subject: Re: [Maxima] Reading matrix and making a plot
To: Dan Kregar <dan.kregar at gmail.com>
Cc: maxima at math.utexas.edu
> Date: Tue, 19 Nov 2013 17:41:21 +0100
> From: Dan Kregar <dan.kregar at gmail.com>
>
> Dear colleagues,
>
> Can somebody please help me with the following problem: I am trying to
> generate a table in a file with three columns for three functions:
>
> with_stdout ("data.txt", for x:0 thru 10 do (
> a:x/1.0,
> b:x^2/1.0,
> c:x^3/1.0,
> print(a,b,c)));
> data: read_matrix("data.txt");
>
> When I read data into Maxima
>
> data: read_matrix("data.txt");
>
> it reads (adds) also tags(!) and not only the array values:
> matrix([<,mth,>,<,n,>,0.0,<,/,n,>,<,st,>,<,/,st,>,<,n,>,0.0,<,/,n,>,<,st,>,
> <,/,st,>,<,n,>,0.0,<,/,n,>,<,st,>,<,/,st,>,<,/,mth,>,<,mth,>,<,n,>,1.0,<,/,
> n,>,<,st,>,<,/,st,>,<,n,>,1.0,<,/,n,>,<,st,>,<,/,st,>,<,n,>,1.0,<,/,n,>,<,s
> t,>,<,/,st,>,<,/,mth,>,<,mth,>,<,n,>,2.0,<,/,n,>,<,st,>,<,/,st,>,<,n,>,4.0,
> <,/,n,>,<,st,>,<,/,st,>,<,n,>,8.0,<,/,n,>,<,st,>,<,/,st,>,<,/,mth,>,<,mth,>
> ,<,n,>,3.0,<,/,n,>,<,st,>,<,/,st,>,<,n,>,9.0,<,/,n,>,<,st,>,<,/,st,>,<,n,>,
> 27.0,<,/,n,>,<,st,>,<,/,st,>,<,/,mth,>,<,mth,>,<,n,>,4.0,<,/,n,>,<,st,>,<,/
> ,st,>,<,n,>,16.0,<,/,n,>,<,st,>,<,/,st,>,<,n,>,64.0,<,/,n,>,<,st,>,<,/,st,>
> ,<,/,mth,>,<,mth,>,<,n,>,5.0,<,/,n,>,<,st,>,<,/,st,>,<,n,>,25.0,<,/,n,>,<,s
> t,>,<,/,st,>,<,n,>,125.0,<,/,n,>,<,st,>,<,/,st,>,<,/,mth,>,<,mth,>,<,n,>,6.
> 0,<,/,n,>,<,st,>,<,/,st,>,<,n,>,36.0,<,/,n,>,<,st,>,<,/,st,>,<,n,>,216.0,<,
> /,n,>,<,st,>,<,/,st,>,<,/,mth,>,<,mth,>,<,n,>,7.0,<,/,n,>,<,st,>,<,/,st,>,<
> ,n,>,49.0,<,/,n,>,<,st,>,<,/,st,>,<,n,>,343.0,<,/,n,>,<,st,>,<,/,st,>,<,/,m
> th,>,<,mth,>,<,n,>,8.0,<,/,n,>,<,st,>,<,/,st,>,<,n,>,64.0,<,/,n,>,<,st,>,<,
> /,st,>,<,n,>,512.0,<,/,n,>,<,st,>,<,/,st,>,<,/,mth,>,<,mth,>,<,n,>,9.0,<,/,
> n,>,<,st,>,<,/,st,>,<,n,>,81.0,<,/,n,>,<,st,>,<,/,st,>,<,n,>,729.0,<,/,n,>,
> <,st,>,<,/,st,>,<,/,mth,>,<,mth,>,<,n,>,10.0,<,/,n,>,<,st,>,<,/,st,>,<,n,>,
> 100.0,<,/,n,>,<,st,>,<,/,st,>,<,n,>,1000.0,<,/,n,>,<,st,>,<,/,st,>,<,/,mth,
> >])
>
> How can I import only "pure" values from 3-values lines into an array (to
> see a nice ASCII atrix)?
>
You are likely using wxmaxima, which is why you see xml crap when you
try to capture stdout and redirect it.
A better idea is to create the list or hashed array in memory, then
use the write_data function to export it to a text file.
(%i1) makelist([x,x^2,x^3],x,0,10);
(%o1) [[0,0,0],[1,1,1],[2,4,8],[3,9,27],[4,16,64],[5,25,125],[6,36,216],
[7,49,343],[8,64,512],[9,81,729],[10,100,1000]]
(%i2) write_data(%o1, "/tmp/data.txt")$
(%i3) l:read_nested_list("/tmp/data.txt");
(%o3) [[0,0,0],[1,1,1],[2,4,8],[3,9,27],[4,16,64],[5,25,125],[6,36,216],
[7,49,343],[8,64,512],[9,81,729],[10,100,1000]]
>
> Next, how can I draw / make a plot with this matrix, where the first
column
> is the independent variable, while the other two vales are its maps
> (functions)?
Something like
(%i4) load(draw)$
(%i5) L(j) := makelist([l[i][1], l[i][j]], i, 1, length(l))$
(%i8) draw2d(points(L(2)), points(L(3)))$
See
http://riotorto.users.sourceforge.net/gnuplot/points/index.html
for more information.
Leo