CoCoA:HowTo:Handle Matlab Matrices

From ApCoCoAWiki

Having a matrix in Matlab and load it into CoCoA4 is not a very easy thing to do. First, the representation is slightly different, second you have to adjust Matlab's IEEE notation of floats into a presentation CoCoA is able to read.

This howto explains, how this can be solved.

Exporting from Matlab to ANSI

The Code to create a almost CoCoa-like list of lists from a Matrix M in Matlab is the following:

S = '['; 
for i=1:1:Rows
      if i == 1
          S = [S, '['];
      else
          S = [S, ',['];
      end;	
      for j=1:1:(Columns-1)
          S = [ S, num2str(M(i,j)),','];
      end;
      S = [ S, num2str(M(i,Columns)),']'];
end;
S = [S,']'];

code by dheldt 12:25, 8 Sep 2005 (CEST) (M is a Rows x Columns - matrix)

No we have something like:

M = [[1,0.333333333];[2,25, 0.000000000000004]]

leads to

S = [[1,0.33333],[2.25,4e-015]]

Importing from ANSI into CoCoA

We have to strip the exponential notation into a CoCoA readable format. My suggestion to achieve this, is using a list construction in CoCoa. This can look like

Use Q[e];
S := ... -- put the String S here

K :=  [     
	[ LC(N)*10^(LC(N - LM(N))  )
	| N In P
	]
      | P In S];

code by dheldt 12:25, 8 Sep 2005 (CEST)

And now we have a list of list K with valid numbers. For example

S := [[1,0.33333],[2.25,4e-015]];

leads to

K :=  [[1, 33333/100000], [9/4, 1/250000000000000];