# Extracting data from Table to do arithmetic operations

I have a code, which goes like this:

ClearAll["Global*"]

c = Table[{x, 2 x, 0 x, N[Sqrt[x]], 0 x}, {x, 0, 20, 2}];

headings = Join[{{"x", "2*x", "imag1", "sqrt(x)", "imag2"}}, c];

const1 = 2;
const2 = 3;


The output is extracted to a dat file “file.dat” which looks like this: Now I need to take each element in the second column, subtract the value of first column from this one and then multiply by a constant and then whole of this value divide by another constant defined in the program. All this value should be collected in another column, say D.

E.g. $$D2=\frac{(x2-B2)\times const1}{const2}$$, $$D3=\frac{(x3-B3)\times const1}{const2}$$, and so on. Similarly, I need to do it for forth column. Ideally, I am expecting the output to look like this: How can I do this?

• const2 is undefined and const1 is defined twice. – Roman May 4 at 15:20
• @Roman it was a typo and has been corrected. Thanks for pointing out. – sreeraj t May 4 at 15:24

See if you can use this

tbl = Table[{x, 2 x, 0 x, N[Sqrt[x]], 0 x}, {x, 0, 20, 2}];
const1 = 2.;
const2 = 3.;
newrow[{a_,b_,c_,d_,e_}]:={a,b,c,(b-a)*const1/const2,d,e,(c-b)*const1/const2};
newtbl=Map[newrow,tbl];
headings = {"x", "2*x", "imag1", "sqrt(x)", "imag2"};

That Map` is going to construct a new row from an existing row and do that for every row in your existing table creating a new table.