parsing rational integers with numericalio



My suggestion is to edit that file by replacing all the spaces with 
commas and insert a comma before each newline.
Then insert a few more characters as ...


M=sparse_matrix(11,11, [ 0,0,1/2, ...


    ])$



and then use loadfile.

You can disentangle the stuff by defining sparse_matrix by, say,

sparse_matrix(rows,cols, stuff):=
block ([ ans:zeromatrix(rows,cols)],
while notequal (stuff,[])  do (ans[stuff[1],stuff[2]]:stuff[3],
                                stuff:rest(stuff,3)),
ans);

example

sparse_matrix(2,2,[1,1,11,2,2,22]);



On 5/19/2011 12:16 PM, andre maute wrote:
> Hi list,
>
> I would like to know, what is the correct way to
> parse the "/" from a read list of numbers in a file
> with the numericalio package?
>
> Thanks
> Andre
>
>
> The file looks as follows and describes a matrix
>
> ------------- readmatrix.txt -------------------
> 11 11
> 0 0 1/2
> 1 1 1/4
> 2 2 1/12
> 3 3 1/6
> 4 4 1/18
> 5 5 1/30
> 6 6 1/8
> 7 7 1/24
> 8 8 1/40
> 9 9 1/56
> 10 10 1/10
> ------------- readmatrix.txt -------------------
>
> my finite state machine to parse the file with the MARKED line
>
> ------------- readmatrix.max -------------------
> display2d : false;
>
> load("numericalio");
>
> matlist : read_list("./readmatrix.txt");
>
> m : first(matlist); matlist : rest(matlist);
> n : first(matlist); matlist : rest(matlist);
>
> /* state 1: read i */
> /* state 2: read j */
> /* state 3: read numerator of A[i,j] */
> /* state 4: read "\/" */
> /* state 5: read denominator of A[i,j] */
> /* state 6: process tuple (i,j,A[i,j]) */
>
> lmatlist : length(matlist);
> state : 1;
> i : -1; j : -1; aij : false; h : false;
> for kk : 1 thru lmatlist do block(
>         if state = 1 then block(
>                 i : first(matlist), matlist : rest(matlist),
>                 state : 2
>         ) else if state = 2 then block(
>                 j : first(matlist), matlist : rest(matlist),
>                 state : 3
>         ) else if state = 3 then block(
>                 aij : first(matlist), matlist : rest(matlist),
>                 /* MARKED HACK */
>                 if not numberp(first(matlist)) then block(
>                         state : 4
>                 ) else block(
>                         state : 6
>                 )
>         ) else if state = 4 then block(
>                 matlist : rest(matlist),
>                 state : 5
>         ) else if state = 5 then block(
>                 aij : aij/first(matlist), matlist : rest(matlist),
>                 state : 6
>         ),
>
>         if state = 6 then block(
>                 print(i,j,aij),
>                 state : 1
>         )
> );
> ------------- readmatrix.max -------------------
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima