Question: How to write data from a matrix to a file while choosing the format?

Dear All,

I would like to know the easiest way to write data, that are stored in a matrix after a computation, to a file with a specific format. To be more precise, I wish to have the possibility to change the format for a given column.

Here is a trial (output is wrote to the terminal for simplification) based on some examples I found, but without success.

WritedataMatrix.mw

How to write data from a matrix to a file while choosing the format

driver := proc () local A, x, f, g, i, P; A := Matrix(3, 3); f := 0.123e124; g := evalf(sin((1/5)*Pi)); i := 0; for x to 3 do i := i+1; A[i, 1] := x; A[i, 2] := f; A[i, 3] := g end do; print(A); writedata(terminal, evalm(A), float); P := proc (A) fprintf(A, `%+08.5f %+08.5f %+08.5f`, A[() .. (), 1], A[() .. (), 2], A[() .. (), 3]) end proc; writedata(terminal, evalm(A), float, P) end proc:

driver()

Matrix([[1, 0.123e124, .5877852524], [2, 0.123e124, .5877852524], [3, 0.123e124, .5877852524]])

 

1        1.23e+123        0.5877852524
2        1.23e+123        0.5877852524
3        1.23e+123        0.5877852524
1        1.23e+123        0.5877852524
2        1.23e+123        0.5877852524
3        1.23e+123        0.5877852524

 

NULL

Download WritedataMatrix.mw

 

Thank you.

Regards.

Please Wait...