Search code examples
arrayscsvmatrixmapleimport-from-csv

Maple: three dimensional fit matrix


I have a CSV file with X values in the first column, and Y values in the first row, with Z values in the middle like so:

**      39       40      41     42 
0.004   2.1802  2.1937  2.2144  2.2379
0.25    1.2409  1.2622  1.2859  1.3073
0.5     1.0538  1.02572 1.04857 1.07059
0.75    0.9479  0.96999 0.98699 1.00675

I can import this into maple as a matrix, but for the maple statistics fit command, it requires the X to be in one column, the Y to be in the second column, and the Z to be in the third column like so:

0.004 39 2.1802
0.004 40 2.1937
0.004 41 2.2144

Is there a way to create the second matrix as Maple wants, or is there a call command for Statistics[Fit] that will allow me to insert the first matrix?


Solution

  • Supposing A is your imported matrix, I create a matrix of three columns X, Y, and Z named XYZ thus:

    n:= LinearAlgebra:-RowDimension(A):
    m:= LinearAlgebra:-ColumnDimension(A):
    XYZ:= Matrix([seq(seq([A[i,1],A[1,j],A[i,j]], j= 2..m), i= 2..n)]):